Thread-safe FloatToSQLStr; StepAndReset -> func

This commit is contained in:
2013-08-30 22:03:19 +07:00
parent b22586e4ef
commit 4d1f752fd8
6 changed files with 35 additions and 27 deletions

View File

@@ -3,8 +3,7 @@ unit Main;
interface interface
uses uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
Dialogs, StdCtrls, ExtCtrls;
type type
TForm_Main = class(TForm) TForm_Main = class(TForm)
@@ -35,7 +34,8 @@ begin
// Delete database if it already exists // Delete database if it already exists
DeleteFile('artists.db'); DeleteFile('artists.db');
// Create datatbase and fill it with example data // Create database and fill it with example data
Screen.Cursor := crHourGlass;
DB := TSQLite3Database.Create; DB := TSQLite3Database.Create;
try try
DB.Open('artists.db'); DB.Open('artists.db');
@@ -163,8 +163,11 @@ begin
finally finally
Stmt.Free; Stmt.Free;
end; end;
ShowMessage('Database created.');
finally finally
DB.Free; DB.Free;
Screen.Cursor := crDefault;
end; end;
end; end;

View File

@@ -7,7 +7,7 @@ object Form_Main: TForm_Main
ClientHeight = 396 ClientHeight = 396
ClientWidth = 657 ClientWidth = 657
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '1.1' LCLVersion = '1.0.12.0'
object Memo_Result: TMemo object Memo_Result: TMemo
Left = 154 Left = 154
Height = 396 Height = 396

View File

@@ -42,7 +42,8 @@ begin
// Delete database if it already exists // Delete database if it already exists
DeleteFile('artists.db'); DeleteFile('artists.db');
// Create datatbase and fill it with example data // Create database and fill it with example data
Screen.Cursor := crHourGlass;
DB := TSQLite3Database.Create; DB := TSQLite3Database.Create;
try try
DB.Open('artists.db'); DB.Open('artists.db');
@@ -170,8 +171,11 @@ begin
finally finally
Stmt.Free; Stmt.Free;
end; end;
ShowMessage('Database created.');
finally finally
DB.Free; DB.Free;
Screen.Cursor := crDefault;
end; end;
end; end;

View File

@@ -1,8 +1,8 @@
{ {
SQLite for Delphi and FreePascal/Lazarus SQLite for Delphi and FreePascal/Lazarus
Copyright 2010-2012 Yury Plashenkov <plashenkov@gmail.com> Copyright 2010-2013 Yury Plashenkov <plashenkov@gmail.com>
http://www.indasoftware.com/sqlite/ http://www.plashenkov.com/projects/sqlite/
SQLite is a software library that implements a self-contained, serverless, SQLite is a software library that implements a self-contained, serverless,
zero-configuration, transactional SQL database engine. The source code for zero-configuration, transactional SQL database engine. The source code for

View File

@@ -1,8 +1,8 @@
{ {
SQLite for Delphi and FreePascal/Lazarus SQLite for Delphi and FreePascal/Lazarus
Copyright 2010-2012 Yury Plashenkov <plashenkov@gmail.com> Copyright 2010-2013 Yury Plashenkov <plashenkov@gmail.com>
http://www.indasoftware.com/sqlite/ http://www.plashenkov.com/projects/sqlite/
SQLite is a software library that implements a self-contained, serverless, SQLite is a software library that implements a self-contained, serverless,
zero-configuration, transactional SQL database engine. The source code for zero-configuration, transactional SQL database engine. The source code for
@@ -44,7 +44,8 @@ function FloatToSQLStr(Value: Extended): WideString;
implementation implementation
uses SysUtils; uses
{$IFNDEF FPC}Windows,{$ENDIF} SysUtils;
function StrToUTF8(const S: WideString): AnsiString; function StrToUTF8(const S: WideString): AnsiString;
begin begin
@@ -82,15 +83,15 @@ end;
function FloatToSQLStr(Value: Extended): WideString; function FloatToSQLStr(Value: Extended): WideString;
var var
SaveSeparator: Char; FS: TFormatSettings;
begin begin
SaveSeparator := DecimalSeparator; {$IFDEF FPC}
DecimalSeparator := '.'; FS := DefaultFormatSettings;
try {$ELSE}
Result := FloatToStr(Value); GetLocaleFormatSettings(GetThreadLocale, FS);
finally {$ENDIF}
DecimalSeparator := SaveSeparator; FS.DecimalSeparator := '.';
end; Result := FloatToStr(Value, FS);
end; end;
end. end.

View File

@@ -1,8 +1,8 @@
{ {
SQLite for Delphi and FreePascal/Lazarus SQLite for Delphi and FreePascal/Lazarus
Copyright 2010-2012 Yury Plashenkov <plashenkov@gmail.com> Copyright 2010-2013 Yury Plashenkov <plashenkov@gmail.com>
http://www.indasoftware.com/sqlite/ http://www.plashenkov.com/projects/sqlite/
SQLite is a software library that implements a self-contained, serverless, SQLite is a software library that implements a self-contained, serverless,
zero-configuration, transactional SQL database engine. The source code for zero-configuration, transactional SQL database engine. The source code for
@@ -102,6 +102,8 @@ type
procedure ClearBindings; procedure ClearBindings;
function Step: Integer; function Step: Integer;
procedure Reset;
function StepAndReset: Integer;
function ColumnCount: Integer; function ColumnCount: Integer;
function ColumnName(const ColumnIndex: Integer): WideString; function ColumnName(const ColumnIndex: Integer): WideString;
@@ -113,9 +115,6 @@ type
function ColumnBlob(const ColumnIndex: Integer): Pointer; function ColumnBlob(const ColumnIndex: Integer): Pointer;
function ColumnBytes(const ColumnIndex: Integer): Integer; function ColumnBytes(const ColumnIndex: Integer): Integer;
procedure Reset;
procedure StepAndReset;
property Handle: PSQLite3Stmt read FHandle; property Handle: PSQLite3Stmt read FHandle;
property OwnerDatabase: TSQLite3Database read FOwnerDatabase; property OwnerDatabase: TSQLite3Database read FOwnerDatabase;
end; end;
@@ -140,7 +139,8 @@ type
implementation implementation
uses SQLite3Utils; uses
SQLite3Utils;
resourcestring resourcestring
SErrorMessage = 'SQLite3 error: %s'; SErrorMessage = 'SQLite3 error: %s';
@@ -390,9 +390,9 @@ begin
Result := sqlite3_step(FHandle); Result := sqlite3_step(FHandle);
end; end;
procedure TSQLite3Statement.StepAndReset; function TSQLite3Statement.StepAndReset: Integer;
begin begin
Step; Result := Step;
Reset; Reset;
end; end;