On Mon, Jul 14, 2003 at 02:26:28PM +0200, Michael Van Canneyt wrote: > > > On Mon, 14 Jul 2003, James Mills wrote: > > > On Mon, Jul 14, 2003 at 09:59:17AM +0200, Michael Van Canneyt wrote: > > > > > > > > > On Mon, 14 Jul 2003, James Mills wrote: > > > > > > > Hi, > > > > > > > > This is a very weird behaviour I've found of either SQLite, or the Unit. > > > > I'm not sure... I have been discussing this same problem on the SQLite > > > > mailing list but without success there, so perhaps someone here might > > > > know... > > > > > > > > I have attached a test database, which contains 1 database entry, null > > > > strings are inserted using NULL... Check the database schema yourself. > > > > > > > > The problem therein lies in the fact that test3.pas returns "" for the > > > > query: SELECT channelNotice FROM channels WHERE channel LIKE '#ProLogiTech'; > > > > It should return a null string as it does in test2.pas and in the sqlite > > > > shell program. > > > > > > The problem is that an implicity conversion from Nil to empty string is > > > done. You cannot solve this as long as stringlists are used to contain > > > the data. (ok, you could set 'Null' as the string, but that is sloppy) > > > > "is done." in what ? The SQLite library or TStringList ? > > sqlite.
But you said "You cannot solve this as long as stringlists are used to contain the data." This made me think it was a behaviour of TStringList ... If it truely is a behaviour of SQLite, I'll get them to change it. > > > > > > > > > You'd need to have (as a minimum) an array of TField records: > > > TField = Record > > > IsNull : Boolean; > > > Value : String; > > > end; > > > > > > But this will require major changes, so I suggest trying to find or > > > implement a TDataset descendent for SQLIte, this will solve most of > > > your problems at once. > > > > How major would the changes be ? Otherwise I'll try and search for a > > TDataset descendent ? Couldn't I write a descendent myself ? (I've kinda > > of done something similar in creating a TDatabase descendant..., but it > > doesn't solve my problem) > > Implementing a TDataset descendent is not easy, it'll take you at least > a week (conservative estimate). Why is this a hard thing to do ? Give me some ideas here, you might be conservative, but I don't muck around :) I'll attach my dbclass.pas a tiny desendant I wrote to simplify using queries (it's centered around making queries simpler)... cheers James > > Michael. > > > _______________________________________________ > fpc-pascal maillist - [EMAIL PROTECTED] > http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- - - James Mills Zero Defect Software Engineers Group - ZDSEG
unit dbClass; interface uses cMem, SQLite, SQLiteDB, Strings, Classes, Functions; type TDatabase = class(TObject) constructor Create; destructor Destroy; override; protected SQL: TSQLite; X: Integer; Y: Integer; S: TStringList; function simpleQuery(query: String): String; function complexQuery(query: String): TStringList; function multiQuery(query: String): TStringList; public end; implementation constructor TDatabase.Create; begin end; destructor TDatabase.Destroy; begin inherited Destroy; if NOT (SQL = nil) then begin SQL.Free; end; end; function TDatabase.simpleQuery(query: String): String; var tmp: String; begin tmp := query; replace('''''', 'NULL', tmp); writeLn('simpleQuery - ', tmp); if NOT (SQL = nil) then begin SQL.Query(tmp, nil); if (SQL.List_Field.count > 0) then begin S := TStringList(SQL.List_Field.items[0]); simpleQuery := S.Strings[0]; end else begin simpleQuery := ''; end; end; end; function TDatabase.complexQuery(query: String): TStringList; var tmp: String; begin tmp := query; replace('''''', 'NULL', tmp); writeLn('complexQuery - ', tmp); if NOT (SQL = nil) then begin SQL.Query(tmp, nil); if (SQL.List_Field.count > 0) then begin complexQuery := TStringList(SQL.List_Field.items[0]); end else begin complexQuery := TStringList.Create; end; end; end; function TDatabase.multiQuery(query: String): TStringList; var temp: String; tmp: String; I: Integer; J: Integer; strs: TStringList; begin temp := query; replace('''''', 'NULL', temp); writeLn('multiQuery - ', temp); if NOT (SQL = nil) then begin SQL.Query(temp, nil); if (SQL.List_Field.count > 0) then begin strs := TStringList.Create; for I := 0 to (SQL.List_Field.Count - 1) do begin tmp := ''; for J := 0 to (TStringList(SQL.List_Field.Items[I]).Count - 1) do begin tmp := tmp + TStringList(SQL.List_Field.Items[I]).Strings[J] + ' '; end; tmp := copy(tmp, 1, (length(tmp) - 1)); strs.add(tmp); end; for I := 0 to (strs.Count - 1) do begin writeLn(I, ' - ', strs.Strings[I]); end; multiQuery := strs; end else begin multiQuery := TStringList.Create; end; end; end; end.