[solved] empty string fields from sqlite being ret. as nulls
Posted: 21.12.2012, 18:39
New to lazarus and zeoslib, so please be gentle
7.0.2 revision 2078
When retrieving data from an sqlite database fields that contain empty strings (not NULL values) are being returned as nulls and causing errors.
Database:
Program:
I'm totally throwing darts, but after some investigation this seemed to fix the problem for me:
File: ZDbcSqLiteResultSet
function TZSQLiteResultSet.InternalGetString
changed line
LastWasNull := Result = '';
to
LastWasNull := Result = null;
Am I even close to doing that right?
7.0.2 revision 2078
When retrieving data from an sqlite database fields that contain empty strings (not NULL values) are being returned as nulls and causing errors.
Database:
Code: Select all
CREATE TABLE settings (
category VARCHAR(40) NULL,
name VARCHAR(40) NULL,
value VARCHAR(250) NULL
)
INSERT INTO settings (category, name, value)
VALUES ("mycat", "myname", "")
Code: Select all
procedure TSettings.LoadSettings;
var
DbQuery: TZReadOnlyQuery;
C: string;
N: string;
V: string;
begin
DbQuery := TZReadOnlyQuery.Create(nil);
DbQuery.Connection := DbConnection;
DbQuery.SQL.Text := 'SELECT * FROM settings';
DbQuery.Open;
while (not DbQuery.EOF) do begin
C := DbQuery['category'];
N := DbQuery['name'];
// get error on the next line: EVariantTypeCastError
// Could not convert variant of type (Null) into type (String)
V := DbQuery['value'];
DbLocalQuery.Next;
end;
DbLocalQuery.Close;
DbLocalQuery.Free;
end;
File: ZDbcSqLiteResultSet
function TZSQLiteResultSet.InternalGetString
changed line
LastWasNull := Result = '';
to
LastWasNull := Result = null;
Am I even close to doing that right?