Page 1 of 1

Error on connect to the SQLite database with Firemonkey IOS app

Posted: Sun 08 Jul 2012 22:34
by josecarlos
I am still trying to get the UniDac Sqlite/IOS working.

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.


Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Mon 09 Jul 2012 14:56
by AlexP
hello,

The sample you have provided works with no errors: a DB can be created and opened, if it exists already. The only place, where an error can occur, is the create table operator, since when a table with such name exists, an error will occur, therefore it is better to add a check IF NOT EXISTS.
P.S. Please specify your xCode and iOS versions

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Mon 09 Jul 2012 19:58
by josecarlos
I got this error on Xcode 4.2 ( IOS 5.0.1 ) and Xcode 4.3.2 ( IOS 5.1 ).

The error happens on the db.connect, and I test it on the iPhone simulator and in a real iPad.

My code worked in your tests, I am reinstalling and checking everything, but on my mac/xcode the line db.connect raises an EXC_BAD_ACCESS and stops on the procedure destroyPixelShader of the unit FMX_Context_GLES.pas.

If you have some idea I will appreciate.

Thanks.

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Tue 10 Jul 2012 08:50
by AlexP
hello,

We checked our components on xCode 3.2.6 (iOS 4.3), maybe the problems are really due to the new versions of the software. We will try to check our products on these versions in the nearest future.
P.S. Please, also make sure that you have an installed FireMonkey-iOS.dmg package from the latest version of RadStudio

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Tue 10 Jul 2012 10:34
by josecarlos
I am using the latest Firemonkey-IOS package from the update 4 Hotfix 1.

So, I am waiting for this fix.

Thanks,

Jose Carlos.

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Sat 14 Jul 2012 15:53
by josecarlos
AlexP wrote:hello,

We checked our components on xCode 3.2.6 (iOS 4.3), maybe the problems are really due to the new versions of the software. We will try to check our products on these versions in the nearest future.
P.S. Please, also make sure that you have an installed FireMonkey-iOS.dmg package from the latest version of RadStudio
How long will take to get the UniDac/Sqlite working with IOS 5 ? I need this to start a new project and bought unidac only for this project.

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Tue 17 Jul 2012 10:30
by AlexP
hello,

The xCode 4.2 and iOS 5.0 support is planned in two weeks. Higher versions of xCode and iOS are presently not supported by RadStudio

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Tue 17 Jul 2012 19:53
by josecarlos
I can't use xCode 3.2.6, this is really bad.

My OSX is LION 10.7.2 and I only have xCode 4 to download, the earlier version is not supported on Lion.

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Tue 31 Jul 2012 08:26
by AlexP
Hello,

We have fixed the problems when connecting to SQLite in iOS 5.0. Now, for developing applications on iOS 5.0, you can use XCode 4.2, the later versions of iOS and Xcode are not supported yet by Embarcadero.
The new UniDAC version 8.3.8 including this fix is already available at our site

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Tue 31 Jul 2012 19:35
by josecarlos
I downloaded yesterday the latest Unidac version, and it is working, Xcode 4.3.2 and IOS 5.1.

Thanks,

Jose Carlos.

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Wed 01 Aug 2012 12:18
by AlexP
hello,

There is the following information at the Embarcadero website ( http://docwiki.embarcadero.com/RADStudi ... up_for_iOS):
Xcode version 3.2.5 to 4.2 verified working.
iOS SDK version 4.2.x, 4.3.x, or 5.0 verified working.
Therefore we checked the workability of our products exactly on these versions, and we cannot guarantee the stable work on later versions of XCode and iOS

Re: Error on connect to the SQLite database with Firemonkey IOS app

Posted: Thu 02 Aug 2012 14:04
by josecarlos
yep, I know that, but so far it is working.

If I get any issue, I will downgrade to IOS 5.0

Thanks.