Skip to content
Browse files

statement: check on prepare was passed invalid handle

  • Loading branch information...
1 parent cd7ff08 commit ac0ce4d6147df2bb89018ab12a6b56a3f8d1827d @stijnsanders committed Nov 23, 2011
Showing with 19 additions and 9 deletions.
  1. +1 −1 SQLiteAdmin/SQLiteAdminMain.dfm
  2. +1 −0 SQLiteAdmin/SQLiteAdminMain.pas
  3. +17 −8 SQLiteData.pas
View
2 SQLiteAdmin/SQLiteAdminMain.dfm
@@ -11,7 +11,7 @@ object formSQLiteAdminMain: TformSQLiteAdminMain
Font.Name = 'Consolas'
Font.Style = []
OldCreateOrder = False
- Position = poMainFormCenter
+ Position = poDefaultPosOnly
DesignSize = (
415
525)
View
1 SQLiteAdmin/SQLiteAdminMain.pas
@@ -56,6 +56,7 @@ procedure TformSQLiteAdminMain.DoCreate;
begin
inherited;
Fdb:=nil;
+ if ParamCount>0 then txtDbPath.Text:=ParamStr(1);
end;
procedure TformSQLiteAdminMain.DoDestroy;
View
25 SQLiteData.pas
@@ -11,6 +11,7 @@ TSQLiteConnection=class(TObject)
function GetLastInsertRowID:int64;
public
constructor Create(FileName:UTF8String);
+ constructor CreateReadOnly(FileName:UTF8String);
destructor Destroy; override;
procedure Execute(SQL:UTF8String); overload;
function Execute(SQL:UTF8String;const Parameters:array of OleVariant):boolean; overload;
@@ -38,7 +39,7 @@ TSQLiteStatement=class(TObject)
function GetParameterCount: integer;
function GetParameterName(Idx: integer): WideString;
function GetEOF: boolean;
- procedure DoInit(Connection:TSQLiteConnection);
+ procedure DoInit;
procedure DoStep;
public
constructor Create(Connection:TSQLiteConnection;SQL:UTF8String); overload;
@@ -84,6 +85,12 @@ constructor TSQLiteConnection.Create(FileName: UTF8String);
sqlite3_check(sqlite3_open(PAnsiChar(FileName),FHandle));
end;
+constructor TSQLiteConnection.CreateReadOnly(FileName: UTF8String);
+begin
+ inherited Create;
+ sqlite3_check(sqlite3_open_v2(PAnsiChar(FileName),FHandle,SQLITE_OPEN_READONLY,nil));
+end;
+
destructor TSQLiteConnection.Destroy;
begin
{sqlite3_check}(sqlite3_close(FHandle));
@@ -171,9 +178,10 @@ constructor TSQLiteStatement.Create(Connection: TSQLiteConnection;
SQL: UTF8String);
begin
inherited Create;
- sqlite3_check(FDB,sqlite3_prepare_v2(Connection.Handle,
+ FDB:=Connection.Handle;
+ sqlite3_check(FDB,sqlite3_prepare_v2(FDB,
PAnsiChar(SQL),Length(SQL),FHandle,PAnsiChar(nil^)));
- DoInit(Connection);
+ DoInit;
end;
constructor TSQLiteStatement.Create(Connection: TSQLiteConnection;
@@ -182,11 +190,12 @@ constructor TSQLiteStatement.Create(Connection: TSQLiteConnection;
x,y:PAnsiChar;
begin
inherited Create;
+ FDB:=Connection.Handle;
x:=PAnsiChar(SQL);
- sqlite3_check(FDB,sqlite3_prepare_v2(Connection.Handle,
+ sqlite3_check(FDB,sqlite3_prepare_v2(FDB,
x,Length(x),FHandle,y));
NextIndex:=integer(y)-integer(x);
- DoInit(Connection);
+ DoInit;
end;
constructor TSQLiteStatement.Create(Connection: TSQLiteConnection;
@@ -195,16 +204,16 @@ constructor TSQLiteStatement.Create(Connection: TSQLiteConnection;
i:integer;
begin
inherited Create;
- sqlite3_check(FDB,sqlite3_prepare_v2(Connection.Handle,
+ FDB:=Connection.Handle;
+ sqlite3_check(FDB,sqlite3_prepare_v2(FDB,
PAnsiChar(SQL),Length(SQL),FHandle,PAnsiChar(nil^)));
- DoInit(Connection);
+ DoInit;
for i:=0 to Length(Parameters)-1 do SetParameter(i+1,Parameters[i]);
end;
procedure TSQLiteStatement.DoInit;
begin
//TODO: tail!
- FDB:=Connection.Handle;
FGotColumnNames:=false;
FGotParamNames:=false;
FOutOfData:=false;

0 comments on commit ac0ce4d

Please sign in to comment.
Something went wrong with that request. Please try again.