This error is happening on UniConnection.Connect; , and I got an EXE_BAD_ACCESS on the Xcode side.
On the code below I am testing two ways to use sqlite and I have two buttons and a memo,
The button btnSQLite3db I put the Hacker's corner sample and it is working.
The button btnUniDac, I am using dimitry's sample and just change the database file name to get the documents folder, when I click this button I got EXE_BAD_ACCESS.
How to fix this?
Is there an IOS sample ?
I am using the latest Unidac source with XE2 Update 4 hot fix 1
Code: Select all
unit Unit2;
{$IFDEF FPC}
{$mode delphi}
{$modeswitch objectivec1}
{$ENDIF}
interface
uses
SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
FMX_Dialogs, DB, DBAccess, UniProvider, SQLiteUniProvider, Uni, FMX_Layouts,
FMX_Memo
{$IFDEF FPC}
, iPhoneAll, SQLite3db, SQLite
{$ENDIF};
type
TForm2 = class(TForm)
btnUnidac: TButton;
btnSQLite3db: TButton;
Memo1: TMemo;
procedure btnUnidacClick(Sender: TObject);
procedure btnSQLite3dbClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.lfm}
{$IFDEF FPC}
function MyDirectory : NSString;
var
paths : NSArray;
fileName : NSString;
begin
paths := NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True);
fileName := paths.objectAtIndex(0);
Result := fileName;
end;
{$ENDIF}
procedure TForm2.btnUnidacClick(Sender: TObject);
var
UniConnection: TUniConnection;
UniQuery: TUniQuery;
begin
UniConnection := TUniConnection.Create(nil);
UniQuery := TUniQuery.Create(nil);
try
UniConnection.ProviderName := 'SQLITE';
UniConnection.Database := String(MyDirectory.UTF8String)+'/UniDac.sqlite';
UniConnection.Connect;
UniConnection.ExecSQL('CREATE TABLE T_TEST (ID INTEGER, NAME VARCHAR(50))',[]);
UniConnection.ExecSQL('INSERT INTO T_TEST VALUES(1, ''Test Name'')',[]);
UniQuery.Connection := UniConnection;
UniQuery.SQL.Text := 'SELECT * FROM T_TEST';
UniQuery.Open;
ShowMessage(UniQuery.FieldByName('ID').AsString + ' - ' + UniQuery.FieldByName('NAME').AsString);
UniQuery.Append;
UniQuery.FieldByName('ID').AsInteger := 2;
UniQuery.FieldByName('NAME').AsString := 'New Name';
UniQuery.Post;
ShowMessage(UniQuery.FieldByName('ID').AsString + ' - ' + UniQuery.FieldByName('NAME').AsString);
UniQuery.Close;
finally
UniQuery.Free;
UniConnection.Free;
end;
end;
procedure TForm2.btnSQLite3dbClick(Sender: TObject);
var
FileName, SQL : String;
DB : TSQLite;
SL : Classes.TStringList;
begin
FileName := String(MyDirectory.UTF8String)+'/MyDB.sqlite';
DB := TSQLite.Create(FileName);
// Create the table
SQL := 'create table Customers (Id integer not null, LastName char(25), FirstName char(25))';
DB.Query(SQL,nil);
// Insert a couple of records
SQL := 'insert into Customers values(1, "Ohlsson", "Anders")';
DB.Query(SQL,nil);
SQL := 'insert into Customers values(2, "Intersimone", "David")';
DB.Query(SQL,nil);
// Get the records back and list them in the memo
SL := Classes.TStringList.Create;
SQL := 'select * from Customers';
if DB.Query(SQL,SL) then
Memo1.Text := SL.Text;
SL.Free;
DB.Free;
end;
end.