When I use a parameterized query (e.g. "SELECT * FROM TABLE WHERE FIELD=?"), sometime I get an Access Violation at line 11719 of dbxopenodbc.pas (v.3.201). Looks like fOdbcParamList is not always initialized. Shouldn't you put something like this?
if (fOdbcParamList=nil) then
begin
fOdbcParamList := TList.Create;
end; { if }
if (fOdbcParamList.Count < ulParameter) then
begin
while fOdbcParamList.Count < ulParameter do
begin
iParam := TOdbcBindParam.Create;
iParam.fOdbcParamNumber := fOdbcParamList.Count + 1;
fOdbcParamList.Add(iParam);
end;
end; { if }
// line 11719
DoExpandParams(ulParameter-1);
aOdbcBindParam := TOdbcBindParam(fOdbcParamList.Items[ulParameter - 1]);
I´m using a Postgres 8.3.4 server with a UTF8 database with ODBC driver psqlodbc_08_03_0200. I'm connecting to it using Delphi 2007. My ODBC DataSource is configured to PostgreSQL Unicode.
Other connection options:
DriverName=PostgresODBC
GetDriverFunc=getSQLDriverODBCW
LibraryName=dbxoodbc.dll
VendorLib=psqlodbc35w.dll
DriverUnit=DBXDynalink
DriverPackageLoader=TDBXDynalinkDriverLoader
DriverPackage=DBXCommonDriver110.bpl
DbxWOterroRBase TransIsolation=ReadCommited
RowsetSize=1
BlobSize=-1
Trim Char=True
Custom String=coLockMode=-1;coCatalog=0;coMapInt64ToBcd=1;coMapCharAsBDE=1
I have seen the same problem, and I think I have a solution.
In my case, I have a nested TClientDataset, when the master calls MoveBy and the detail calls TCustomSQLDataSet.RefreshParams, we eventually end up in TSqlCommandOdbc.SetParameter which calls DoExpandParams. When there is a single parameter, the integer (ulParameter-1) is passed into DoAllocateParams. This causes the problem because you now have the situation where fOdbcParamList = nil AND ParamCount = 0, so fOdbcParamList does not get created in DoAllocateParams.
If you look at any other place where DoExpandParams is called, such as the Prepare code upon initial opening, the parameter being passed to DoExpandParams represents a true ParamCount...but with TSqlCommandOdbc.SetParameter, it simply subtracts 1 from the input parameter "ulParameter", which in this context is the iFldNum variable from the procedure SetQueryParams in SqlExpr.pas.
Changing this single line so that it stops subtracting 1 from "ulParameter" has solved my issue, and I can't see any negative side effects.
Can somebody confirm or deny my findings?
I am commited the latest version with your changes.
dbx version: 3.207, 2009-03-10
Diff to previous: http://open-dbexpress.cvs.sourceforge.net/viewvc/open-dbexpress/dbxoodbc/DbxOpenOdbc.pas?r1=1.111&r2=1.112
Take last version with CVS: http://open-dbexpress.cvs.sourceforge.net/viewvc/open-dbexpress/dbxoodbc/
Thanks "alienhunter1" !