Subject connection lost when changing sort order
Author Markus Ostenried
Hi all,

first of all, sorry for the large message - I just wanted to include all
the necessary information.

The client application runs on WinXP Pro, I'm using Delphi 5.
The error appears with IBO 4.3 He and IBO 4.4 Aa.
I tested it with Firebird 1.03 Windows (connection string:
<server-name>:<local-path-to-db>) and Firebird 1.5 RC5 CS Linux
(connection-string: <server-ip>:<alias-name>) both using TCP/IP.

I'm having a strange problem with one of my queries:
When I change the sort order by clicking on the header of my IB_Grid's
KTO_OWNERSTRING column the connection to the server is lost.
KTO_OWNERSTRING is computed by a stored procedure and contains the value of
column KTO_NAME. KTO_NAME contains special german characters (like ä, ö, ü, ß).
Note: refreshing the query, inserting, deleteing, updating and scrolling
works fine.

<Query>
SELECT KTO_ID_KONTO
, KTO_OWNERSTRING
, KTO_NAME
, KTO_OWNERSTRING || ' - ' || KTO_NAME AS KTO_OWNER_AND_NAME
, KTO_ID_OWNER
, KTO_OWNERTYPE
, KTO_BSTYPE
, KTO_GUNDV
, KTO_SUMHABEN
, KTO_SUMSOLL
, KTO_SUM
, KTO_CREATEDAT
, KTO_CREATEDBY
, KTO_LASTCHANGEDAT
, KTO_LASTCHANGEDBY
FROM KONTO
//ORDER BY
FOR UPDATE
</Query>

<OrderingItems>
KTO_OWNERSTRING=KTO_OWNERSTRING;KTO_OWNERSTRING DESC
KTO_NAME=KTO_NAME,KTO_OWNERSTRING;KTO_NAME DESC,KTO_OWNERSTRING DESC
</OrderingItems>

<OrderingLinks>
KTO_OWNERSTRING=ITEM=1
KTO_NAME=ITEM=2
</OrderingLinks>

OrderingItemNo = 1

<Table-DDL>
create table KONTO(
KTO_ID_KONTO integer not null,
KTO_ID_OWNER integer not null,
KTO_OWNERTYPE D_KONTOOWNERTYPE collate ISO8859_1,
KTO_BSTYPE D_KONTOBSTYPE collate ISO8859_1,
KTO_NAME varchar(120) character set ISO8859_1 not null collate DE_DE,

KTO_OWNERSTRING computed by (( SELECT out_Owner FROM
P_GETKTOOWNERSTRING(KONTO.KTO_ID_OWNER, KONTO.KTO_OWNERTYPE) )),

KTO_SUMHABEN computed by (( SELECT SUM(KBS.KBS_BETRAG) FROM KONTOBS
KBS WHERE (KBS.KBS_ID_KONTO = KONTO.KTO_ID_KONTO) AND (KBS.KBS_BETRAG > 0) )),
KTO_SUMSOLL computed by (( SELECT SUM(KBS.KBS_BETRAG) FROM KONTOBS
KBS WHERE (KBS.KBS_ID_KONTO = KONTO.KTO_ID_KONTO) AND (KBS.KBS_BETRAG < 0) )),
KTO_SUM computed by (( SELECT SUM(KBS.KBS_BETRAG) FROM KONTOBS KBS
WHERE (KBS.KBS_ID_KONTO = KONTO.KTO_ID_KONTO) )),
KTO_CREATEDAT D_CREATEDAT,
KTO_CREATEDBY D_CREATEDBY collate ISO8859_1,
KTO_LASTCHANGEDAT D_LASTCHANGEDAT,
KTO_LASTCHANGEDBY D_LASTCHANGEDBY collate ISO8859_1,
KTO_GUNDV D_BOOLEAN not null collate ISO8859_1);
/* Primary Key */
alter table KONTO add constraint PK_KONTO primary key (KTO_ID_KONTO);
</Table-DDL>

<StoredProc-DDL>
create procedure P_GETKTOOWNERSTRING (
IN_ID_OWNER integer,
IN_OWNERTYPE varchar(50) character set ISO8859_1)
returns (
OUT_OWNER varchar(500) character set ISO8859_1)
as
DECLARE VARIABLE var_OwnerType VARCHAR(50);
DECLARE VARIABLE var_s01 VARCHAR(100);
DECLARE VARIABLE var_s02 VARCHAR(100);
DECLARE VARIABLE var_s03 VARCHAR(100);
BEGIN
var_s01 = NULL;
var_s02 = NULL;
var_s03 = NULL;

/* Kunde */
IF (in_OwnerType = 'KUNDE') THEN BEGIN
var_OwnerType = 'Kunde: ';
SELECT KD_NACHNAME || ', '
, KD_VORNAME
FROM KUNDE
WHERE (KD_ID_KUNDE = :in_ID_Owner)
INTO :var_s01, :var_s02;
END ELSE

/* Firma */
IF (in_OwnerType = 'FIRMA') THEN BEGIN
var_OwnerType = 'Firma: ';
SELECT FI_FIRMENNAME1
FROM FIRMA
WHERE (FI_ID_FIRMA = :in_ID_Owner)
INTO :var_s01;
END

/* unknown */
ELSE BEGIN
var_OwnerType = in_OwnerType || ': ';
END

out_Owner = var_OwnerType;
IF (var_s01 IS NOT NULL) THEN out_Owner = out_Owner || var_s01;
IF (var_s02 IS NOT NULL) THEN out_Owner = out_Owner || var_s02;
IF (var_s03 IS NOT NULL) THEN out_Owner = out_Owner || var_s03;
SUSPEND;
END
</StoredProc-DDL>

and that's what IB_Monitor says, when I try to change the sort order:
<monitor>
/*---
[ 05.12.2003 11:08:58 ]
PREPARE STATEMENT
TR_HANDLE = 18889540
STMT_HANDLE = 32090564

SELECT KTO_ID_KONTO
, KTO_OWNERSTRING
, KTO_NAME
, KTO_OWNERSTRING || ' - ' || KTO_NAME AS KTO_OWNER_AND_NAME
, KTO_ID_OWNER
, KTO_OWNERTYPE
, KTO_BSTYPE
, KTO_GUNDV
, KTO_SUMHABEN
, KTO_SUMSOLL
, KTO_SUM
, KTO_CREATEDAT
, KTO_CREATEDBY
, KTO_LASTCHANGEDAT
, KTO_LASTCHANGEDBY

FROM KONTO



ORDER BY KTO_OWNERSTRING DESC


PLAN (KUNDE INDEX (RDB$PRIMARY1))(FIRMA INDEX (RDB$PRIMARY26))
PLAN (KONTOBS INDEX (RDB$FOREIGN34))
PLAN (KONTOBS INDEX (RDB$FOREIGN34))
PLAN (KONTOBS INDEX (RDB$FOREIGN34))
PLAN (KUNDE INDEX (RDB$PRIMARY1))(FIRMA INDEX (RDB$PRIMARY26))
PLAN (KUNDE INDEX (RDB$PRIMARY1))(FIRMA INDEX (RDB$PRIMARY26))
PLAN SORT ((KONTO NATURAL))

FIELDS = [ Version 1 SQLd 15 SQLn 32
KONTO.KTO_ID_KONTO = <NIL>
KONTO.KTO_OWNERSTRING[KTO_OWNERSTRING] = <NIL>
KONTO.KTO_NAME = <NIL>
[KTO_OWNER_AND_NAME] = <NIL>
KONTO.KTO_ID_OWNER = <NIL>
KONTO.KTO_OWNERTYPE = <NIL>
KONTO.KTO_BSTYPE = <NIL>
KONTO.KTO_GUNDV = <NIL>
KONTO.KTO_SUMHABEN = <NIL>
KONTO.KTO_SUMSOLL = <NIL>
KONTO.KTO_SUM = <NIL>
KONTO.KTO_CREATEDAT = <NIL>
KONTO.KTO_CREATEDBY = <NIL>
KONTO.KTO_LASTCHANGEDAT = <NIL>
KONTO.KTO_LASTCHANGEDBY = <NIL> ]

SECONDS = 0,010
----*/
/*===
[ 05.12.2003 11:08:58 ]
//>>> STATEMENT PREPARED <<<//
TIB_Statement.API_Prepare()
TIB_Query: "M_DM3.Qry_Konto" stHandle=32090564
====*/
/*---
[ 05.12.2003 11:08:58 ]
EXECUTE STATEMENT
TR_HANDLE = 18889540
STMT_HANDLE = 32090564
PARAMS = [ ]

SELECT COUNT: 12
----*/
/*---
[ 05.12.2003 11:08:58 ]
OPEN CURSOR
STMT_HANDLE = 32090564
NAME = C34704720318148129

----*/
/*---
[ 05.12.2003 11:08:58 ]
PREPARE STATEMENT
TR_HANDLE = 18889540
STMT_HANDLE = 32077072

SELECT KTO_ID_KONTO
, KTO_OWNERSTRING
, KTO_NAME
, KTO_OWNERSTRING || ' - ' || KTO_NAME AS KTO_OWNER_AND_NAME
, KTO_ID_OWNER
, KTO_OWNERTYPE
, KTO_BSTYPE
, KTO_GUNDV
, KTO_SUMHABEN
, KTO_SUMSOLL
, KTO_SUM
, KTO_CREATEDAT
, KTO_CREATEDBY
, KTO_LASTCHANGEDAT
, KTO_LASTCHANGEDBY

FROM KONTO



WHERE KONTO.KTO_ID_KONTO=? /* BIND_0 */


PLAN (KONTOBS INDEX (RDB$FOREIGN34))
PLAN (KONTOBS INDEX (RDB$FOREIGN34))
PLAN (KONTOBS INDEX (RDB$FOREIGN34))
PLAN (KUNDE INDEX (RDB$PRIMARY1))(FIRMA INDEX (RDB$PRIMARY26))
PLAN (KUNDE INDEX (RDB$PRIMARY1))(FIRMA INDEX (RDB$PRIMARY26))
PLAN (KONTO INDEX (RDB$PRIMARY22))

FIELDS = [ Version 1 SQLd 15 SQLn 15
KONTO.KTO_ID_KONTO = <n> 0
KONTO.KTO_OWNERSTRING = <NULL>
KONTO.KTO_NAME = <n> ''
[KTO_OWNER_AND_NAME] = <NULL>
KONTO.KTO_ID_OWNER = <n> 0
KONTO.KTO_OWNERTYPE = <n> ''
KONTO.KTO_BSTYPE = <n> ''
KONTO.KTO_GUNDV = <n> ''
KONTO.KTO_SUMHABEN = <NULL>
KONTO.KTO_SUMSOLL = <NULL>
KONTO.KTO_SUM = <NULL>
KONTO.KTO_CREATEDAT = <n> '17 Nov 1858'
KONTO.KTO_CREATEDBY = <n> ''
KONTO.KTO_LASTCHANGEDAT = <n> '17 Nov 1858'
KONTO.KTO_LASTCHANGEDBY = <n> '' ]

SECONDS = 0,010
----*/
/*===
[ 05.12.2003 11:08:58 ]
//>>> STATEMENT PREPARED <<<//
TIB_BindingCursor.GetPrepare()
TIB_BindingCursor: "Qry_Konto." stHandle=32077072 #BC

TIB_BindingCursor.BDataset =
TIB_Query: "M_DM3.Qry_Konto"
====*/
/*---
[ 05.12.2003 11:08:58 ]
DESCRIBE INPUT
STMT_HANDLE = 32077072
PARAMS = [ Version 1 SQLd 1 SQLn 1
< SQLType: 496 SQLLen: 4 > = <n> 0 ]
----*/
/*---
[ 05.12.2003 11:08:58 ]
EXECUTE ROW FETCH
TR_HANDLE = 18889540
STMT_HANDLE = 32077072
PARAMS = [ Version 1 SQLd 1 SQLn 1
KONTO.KTO_ID_KONTO[BIND_0] = 13 ]

SECONDS = 0,020
----*/
/*---
[ 05.12.2003 11:08:58 ]
OPEN ROW CURSOR
STMT_HANDLE = 32077072
NAME = C34711112238148128
----*/
/*---
[ 05.12.2003 11:08:58 ]
FETCH
STMT_HANDLE = 32077072
FIELDS = [ Version 1 SQLd 15 SQLn 15
KONTO.KTO_ID_KONTO = <n> 13
KONTO.KTO_OWNERSTRING = 'Kunde: '
KONTO.KTO_NAME = <n> 'regelmaessige Zahlungen'
[KTO_OWNER_AND_NAME] = 'Kunde: - regelmaessige Zahlungen'
KONTO.KTO_ID_OWNER = <n> 6
KONTO.KTO_OWNERTYPE = <n> 'KUNDE'
KONTO.KTO_BSTYPE = <n> 'AUTO'
KONTO.KTO_GUNDV = <n> 'F'
KONTO.KTO_SUMHABEN = <NULL>
KONTO.KTO_SUMSOLL = <NULL>
KONTO.KTO_SUM = <NULL>
KONTO.KTO_CREATEDAT = <n> '02 Dez 2003 16:33:57'
KONTO.KTO_CREATEDBY = <n> 'OZ'
KONTO.KTO_LASTCHANGEDAT = <n> '02 Dez 2003 16:33:57'
KONTO.KTO_LASTCHANGEDBY = <n> 'OZ' ]
----*/
/*---
[ 05.12.2003 11:08:58 ]
FETCH
STMT_HANDLE = 32077072
FIELDS = [ Version 1 SQLd 15 SQLn 15
KONTO.KTO_ID_KONTO = <n> 13
KONTO.KTO_OWNERSTRING = 'Kunde: '
KONTO.KTO_NAME = <n> 'regelmaessige Zahlungen'
[KTO_OWNER_AND_NAME] = 'Kunde: - regelmaessige Zahlungen'
KONTO.KTO_ID_OWNER = <n> 6
KONTO.KTO_OWNERTYPE = <n> 'KUNDE'
KONTO.KTO_BSTYPE = <n> 'AUTO'
KONTO.KTO_GUNDV = <n> 'F'
KONTO.KTO_SUMHABEN = <NULL>
KONTO.KTO_SUMSOLL = <NULL>
KONTO.KTO_SUM = <NULL>
KONTO.KTO_CREATEDAT = <n> '02 Dez 2003 16:33:57'
KONTO.KTO_CREATEDBY = <n> 'OZ'
KONTO.KTO_LASTCHANGEDAT = <n> '02 Dez 2003 16:33:57'
KONTO.KTO_LASTCHANGEDBY = <n> 'OZ' ]

ERRCODE = 100
----*/
/*---
[ 05.12.2003 11:08:58 ]
CLOSE ROW CURSOR
STMT_HANDLE = 32077072

SECONDS = 0,010
----*/
/*---
[ 05.12.2003 11:08:58 ]
ALLOCATE STATEMENT
DB_HANDLE = 18896616
STMT_HANDLE = 32011256
----*/
/*---
[ 05.12.2003 11:08:58 ]
PREPARE STATEMENT
TR_HANDLE = 18889540
STMT_HANDLE = 32011256

SELECT KONTO.KTO_ID_KONTO
FROM KONTO
WHERE KONTO.KTO_ID_KONTO=?

PLAN (KONTO INDEX (RDB$PRIMARY22))

FIELDS = [ Version 1 SQLd 1 SQLn 1
KONTO.KTO_ID_KONTO = 13 ]
----*/
/*===
[ 05.12.2003 11:08:58 ]
//>>> STATEMENT PREPARED <<<//
TIB_BDataset.SysLookupKeyForBufferFields.GetSeekCursor()
TIB_Query: "M_DM3.Qry_Konto" stHandle=32011256 #SC
====*/
/*---
[ 05.12.2003 11:08:58 ]
EXECUTE STATEMENT
TR_HANDLE = 18889540
STMT_HANDLE = 32011256
PARAMS = [ Version 1 SQLd 1 SQLn 1
KONTO.KTO_ID_KONTO = 13 ]
----*/
/*---
[ 05.12.2003 11:08:58 ]
OPEN CURSOR
STMT_HANDLE = 32011256
NAME = 32011256C34704720318148129


SECONDS = 0,010
----*/
/*---
[ 05.12.2003 11:08:58 ]
FETCH
STMT_HANDLE = 32011256
FIELDS = [ Version 1 SQLd 1 SQLn 1
KONTO.KTO_ID_KONTO = 13 ]
----*/
/*---
[ 05.12.2003 11:08:58 ]
CLOSE CURSOR
STMT_HANDLE = 32011256
----*/
/*---
[ 05.12.2003 11:08:58 ]
FETCH
STMT_HANDLE = 32090564
FIELDS = [ Version 1 SQLd 15 SQLn 15
KONTO.KTO_ID_KONTO = 9
KONTO.KTO_OWNERSTRING = 'Kunde: Wiedenhorn, Frank'
KONTO.KTO_NAME = 'Zahlungen regelmäßig'
[KTO_OWNER_AND_NAME] = 'Kunde: Wiedenhorn, Frank - Zahlungen regelmäßig'
KONTO.KTO_ID_OWNER = 5
KONTO.KTO_OWNERTYPE = 'KUNDE'
KONTO.KTO_BSTYPE = 'AUTO'
KONTO.KTO_GUNDV = 'F'
KONTO.KTO_SUMHABEN = <NULL>
KONTO.KTO_SUMSOLL = <NULL>
KONTO.KTO_SUM = <NULL>
KONTO.KTO_CREATEDAT = '09 Nov 2003 18:27:01'
KONTO.KTO_CREATEDBY = 'OZ'
KONTO.KTO_LASTCHANGEDAT = '12 Nov 2003 22:27:16'
KONTO.KTO_LASTCHANGEDBY = 'OZ' ]

SECONDS = 0,120

ERRCODE = 335544726
----*/
/*---
[ 05.12.2003 11:08:58 ]
INTERPRETE BUFFER =

ERRCODE = 39
----*/
/*---
[ 05.12.2003 11:08:58 ]
INTERPRETE BUFFER = Error reading data from the connection.

ERRCODE = -1
----*/
/*---
[ 05.12.2003 11:08:58 ]
FETCH
STMT_HANDLE = 32090564
FIELDS = [ Version 1 SQLd 15 SQLn 15
KONTO.KTO_ID_KONTO = 9
KONTO.KTO_OWNERSTRING = 'Kunde: Wiedenhorn, Frank'
KONTO.KTO_NAME = 'Zahlungen regelmäßig'
[KTO_OWNER_AND_NAME] = 'Kunde: Wiedenhorn, Frank - Zahlungen regelmäßig'
KONTO.KTO_ID_OWNER = 5
KONTO.KTO_OWNERTYPE = 'KUNDE'
KONTO.KTO_BSTYPE = 'AUTO'
KONTO.KTO_GUNDV = 'F'
KONTO.KTO_SUMHABEN = <NULL>
KONTO.KTO_SUMSOLL = <NULL>
KONTO.KTO_SUM = <NULL>
KONTO.KTO_CREATEDAT = '09 Nov 2003 18:27:01'
KONTO.KTO_CREATEDBY = 'OZ'
KONTO.KTO_LASTCHANGEDAT = '12 Nov 2003 22:27:16'
KONTO.KTO_LASTCHANGEDBY = 'OZ' ]

ERRCODE = 335544721
----*/
/*---
[ 05.12.2003 11:08:58 ]
INTERPRETE BUFFER =

ERRCODE = 50
----*/
/*---
[ 05.12.2003 11:08:58 ]
INTERPRETE BUFFER = Unable to complete network request to host "VMD5".

ERRCODE = 37
----*/
/*---
[ 05.12.2003 11:08:58 ]
INTERPRETE BUFFER = Error writing data to the connection.

SECONDS = 0,011

ERRCODE = 64
----*/
/*---
[ 05.12.2003 11:08:58 ]
INTERPRETE BUFFER = An existing connection was forcibly closed by the
remote host.


ERRCODE = -1
----*/
</monitor>


Any hints are greatly appreciated,
TIA,
Markus