iOS FireDac sqlite database problem (when deployed with the app)

I need to access a sqlite database that is provided with the app. I am using Firedac to access it. It works as intended on Win32, but does NOT on the iOS Simulator and iOS Device. 

I am using XE4, with the ADConnection, ADQuery, ADGUIxWaitCursor,ADPhysSQLiteDriverLink and ADMoniCustomClientLink components.

When I deploy the database file (under “.\Startup\Documents\”  ) , the file is recognized as existing, but the app crashes with a Runtime error 231 after the SQL query has been set off. The documentation states that the deployment path should be “Startup\...” without the “.\” , but then the database is not recognized with fileexists.

Interestingly, I can, on all platforms, create a sqlite database, fill it with data, read it, but when I want to deploy it again (without creating it), it cannot be read any more on iOS platforms.

The driver is statically linked on Win32 and dynamically on iOS.

This is the SQL Query code

{code}
dodebug('===== START of PROCEDURE bOpenExistingDBClick');
ADConnection1.Params.Values['Database']:=DBName;
dodebug('Open DB');
ADConnection1.Connected := true;
dodebug('SQL Query');
sql:='SELECT id,Nr,Name,Data FROM tbl_data';
ADQuery1.SQL.Clear;
ADQuery1.SQL.Add(sql);
ADQuery1.Active:= true;
ADQuery1.First;
ts:= TStringList.Create;
while Not(ADQuery1.Eof ) do
  begin
  i    := ADQuery1.FieldByName('id').AsInteger;
  Nr   := ADQuery1.FieldByName('Nr').AsInteger;
  Name := ADQuery1.FieldByName('Name').AsString;
  Data := ADQuery1.FieldByName('Data').AsFloat;

  t:= format('%3d [ %3d ] = %15s   %15.13f',[i,nr,name,data]);
  ts.Add(t);
  ADQuery1.Next;
  end;
dodebug('Close DB');
ADConnection1.Connected := false;
{code}

To help diagnose the situation, I found it useful, to use the following debug procedure, as it produces all the events in the Eventlog on Windows, and on the relevant consoles for iOS:

{code}
{$IFDEF iOS}
uses iOSApi.Foundation, iOSApi.CocoaTypes, MacAPI.ObjectiveC;
{$ENDIF}
{$IFDEF MSWINDOWS}
uses Windows;
{$ENDIF}

{$R *.fmx}
procedure dodebug( debugString : string);
var
  t : string;
  c : char;
  i : longint;
{$IFDEF iOS}
 iOSString: NSString;
 iOSPointer: Pointer;
{$ENDIF}
begin
//AppStartTime is a global TDateTime variable which is set in FormCreate:  AppStartTime:=now;
t:=format('-----> %8.3f = ',[(now-AppStartTime)*86400]);
for i := 0 to length(debugString)-1 do
  begin
  c := debugString[i];
  if not( (c = chr(13)) or (c=chr(10)) ) then t:=t+c;
  end;
{$IFDEF iOS}
iOSString:=NSStr(t);
iOSPointer := (iosString as ILocalObject).GetObjectID;
NSlog(iosPointer);
{$ENDIF}
{$IFDEF MSWINDOWS}
OutputDebugString(pchar(t));
{$ENDIF}
end;{code}

Furthermore, all FireDac Monitoring Messages can be sent there with the ADMoniCustonClientLink component and the following code:

{code}
procedure TForm1.ADMoniCustomClientLink1Output(ASender: TADMoniClientLinkBase;
  const AClassName, AObjName, AMessage: string);
begin
dodebug('[FireDAC]: '+AClassName+' - '+AObjName+' - '+AMessage);
end; 
{code}

I could provide the complete testing code, but I don’t know how I should do this.

Any help would be very much appreciated. 

Thank you,
Martin
0
Martin
5/14/2013 7:55:26 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

3 Replies
1973 Views

Similar Articles

[PageSpeed] 30

Hello Martin

> The documentation states that the deployment path should be “Startup\...”
> without the “.\” , but then the database is not recognized with 
> fileexists.

The deployment path must be "Startup\Documents".
The FireDAC Database parameter value then can be:

ADConnection1.Params.Values['Database']:='$(DOC)/db.sdb';

More about FireDAC path variables:
http://docs.embarcadero.com/products/rad_studio/firedac/Path_Variables.html

Also note, that assigning connection definition parameters
as above, you can leave old parameter values in Params.
Better to do:

ADConnection1.Params.Clear;
ADConnection1.Params.Add('DriverID=SQLite');
ADConnection1.Params.Add('Database=$(DOC)/db.sdb)';

> I could provide the complete testing code, but I don’t know how I should 
> do this.

You can create a simple test project (including project
deployment settings), reproducing the issue and post it to
embarcadero.public.attachments newsgroup. And post
in a "normal" newsgroup a note that you posted attachment.

-- 
With best regards,
Dmitry Arefiev / FireDAC Architect
FireDAC - Firebird, SQLite, MySQL, SQL Server, Oracle, PostgreSQL,
DB2, SQL Anywhere, Access, Informix, ODBC high-speed data access lib
0
Dmitry
5/15/2013 7:16:43 AM
Hello Dmitry,

Thank you for your fast response and advice.

I have read the documentation before and I used exactly the folders you have provided. As this did not work I started with looking into the case in more detail.

I have added your connection parameter definition to the code and the path variables again, and now I get an exception: SIGSEGV (11)

Here is the link to the complete project:
https://forums.embarcadero.com/thread.jspa?threadID=87346&stqc=true

It is really just for testing. It can create a sqlite database (test.db). 
The intention was then to copy this file and rename it to testOffline.db  
Then deploy the testOffline.db with the app.
And then open this file from the app.

A comment to your statement that:  the deployment path must be "Startup\Documents"
I assume that this is a current FireDAC limitation, as Apple allows to put files into different folders depending what somebody wants to do with them. 
Example:

Documents\   …  files for backup
Library\    …  for files that do not need backup
Temp\  … the usual
And even into the AppName.app  folder for files that shall not be changed ( I actually have an app in the store using this method) 

See Documentation “iOS Standard Directories: Where Files Reside” in “File System Basics”

I would be interested if FireDAC is going to allow the use of any other directory then Documents in the future? 

The reason for me to look into using FireDAC is cross-multi-platform development, and I would prefer anyway to indicate the path in absolute form to the database driver. Is this / will this be possible?

Thank you and best regards,
Martin

Edited by: Martin Frankl on May 15, 2013 11:26 PM
0
Martin
5/16/2013 6:27:11 AM
Martin, thank you for test application.

> I have added your connection parameter definition to the code and the path
> variables again, and now I get an exception: SIGSEGV (11)

I reproduced this issue by pressing on "Open OFFLINE DB ...".
The issue requires additional investigation. As a workaround please
set FADGUIxSilentMode to True in FormCreate.

> A comment to your statement that:  the deployment path must be 
> "Startup\Documents"
> I assume that this is a current FireDAC limitation, as Apple allows to put 
> files into
> different folders depending what somebody wants to do with them.

My point was not that you should use only "Startup\Documents"
folder, but that should not prepend "Startup" with dot / slash.
Of course, you can put a DB file to whatever place you like and
specify as a Database parameter value any one path, including
absolute.

> Documents\   …  files for backup

Is a convenient path for DB files.

-- 
With best regards,
Dmitry Arefiev / FireDAC Architect
FireDAC - Firebird, SQLite, MySQL, SQL Server, Oracle, PostgreSQL,
DB2, SQL Anywhere, Access, Informix, ODBC high-speed data access lib
0
Dmitry
5/16/2013 8:34:56 AM
Reply:

Similar Artilces:

Problems with IOS Deployment
Continuing to have problems with the deployment of the app on a iPad. Running XE4, OSX 10.9.1, xcode 5.02 The application runs fine in the simulator and attempts to run on the device. I have made certain that the file is deployed in the StartUp\Documents\ folder. I have tried to set the SQLConnection in both the Form.OnCreate and on the SQLConnection.beforeConnect If i execute a FileExists Command on the SQLConnection.params.database it returns file not found. I have tried with multiple small apps and it continues to hang or just not run at all. Any suggestions would be appre...

iOS FireDac sqlite database problem: Sample Project
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_896a4.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" See thread https://forums.embarcadero.com/thread.jspa?threadID=87295&tstart=0 for details. Thanks, Martin --JivePart=_896a4.zeB8CwDOH5aMJzMl Content-Type: application/x-7z-compressed; name="xe4_bug_sqlite.7z" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="xe4_bug_sqlite.7z" N3q8ryccAAMeqBU...

Database problem with deployed database app. on WinNT.
Dear fellow Power Builder users. I have a serious problem that occurs when I deploy my Power Builder application on WindowsNT. I am using: PB 7.0 build 6012 WindowsNT 4.0 service pack 5 Adaptive Server Anywhere 6.0.2 When I start the application the databases are started and the following error occurs: "Failed to initialized NT performance monitor data area." The error is showed on the top of the log in the console window for the database engine. When I try to retrieve data from the database I get SQLSTATE=37000. None of the above errors occur on Win95. I use t...

Problems with sqlite database on firemonkey
Hi Guys I'm testing the delphi XE5. I created a new project for a mobile application of firemonkey. My intention is simple, write the contents of an edit in a field of a table in a SQLite database using FireDAC with less code as possible. To do this I placed in a clean form: a FDPhysSQLiteDriverLink, a FDGUIxWaitCursor, a FDConnection, a FDQuery, a FDUpdateSQL, a BindSourceDB, a BindingList, a NavigatorBindSourceDB, and a Tedit. I have configured connection, I have inserted SQL commands in FDQuery and FDUpdateSQL and I have attached all using the livebinding designer. I c...

Deploy SQLite database to iOS device
Hi to everyone, I want to Deploy a SQLite database to the device. I created the database under windows32. Deploying to startup/documets works. But when I try to use the database on the device I get "database disk image is malformed". On the simulator this works fine. Is it impossible to deploy SQLite database files to device? -- Best Regards from Berlin Edgar Hello, I did it successfully using this tutorial: http://docwiki.embarcadero.com/RADStudio/XE4/en/IOS_Tutorial:_Using_SQLite_in_an_iOS_Application Hope it will help you... > {quote:title=Edgar Leifeld wro...

Problem with FireDAC using SQLite on iOS
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_8e73e.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" Refer to my post with the same title in delphi.database.firedac -- Dave Nottage [TeamB] --JivePart=_8e73e.zeB8CwDOH5aMJzMl Content-Type: application/octet-stream; name="iOSSQLiteFireDAC.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="iOSSQLiteFireDAC.zip" UEsDBBQAAAAIAI9+/ELxgF8JRwAAAIAAAAAgAAAA...

SQLite database deployment to iOS simulator
Me again!! My app uses an sqlite db. I've added this to the 'deployment' section and hit 'deploy'. 'Remote status' shows 'same' so I assume it's now installed on the Mac. However, when I run the app in the simulator I get 'Unable to open database'. I'm setting the database as below - is this correct? I've tried ./mydb.db as well. {code} SQLConnection1.Params.Add('Database=mydb.db'); {code} > {quote:title=martin moore wrote:}{quote} > Me again!! > > My app uses an sqlite db. I've added this to t...

Problem with FireDAC using SQLite on iOS
I'm having issues with using FireDAC to write to a SQLite database on iOS, namely that some values disappear, and others come out as garbage, at least in the simulator. Please refer to the test project in the attachments group. Please also excuse the slightly extraneous stuff: it is related to issues I was having with LiveBindings, which has a workaround included in the project. Clicking Add then filling out the data, then clicking Save, all appears to be ok, until you navigate off the record, then back to it. -- Dave Nottage [TeamB] Dave, Your problem seems similar to w...

Problem in running IOS app
Hi, i have delphi 6 and a mac mavericks 10.9.3 with Xcode 6 beta installed with command line tools for mavericks, the problem is after creating a correct profile and sdk in delphi, when im trying to run a simple app i face this error in IOS Device mode: [DCC Error] E2597 ld: file not found: /usr/lib/system/libsystem_coretls.dylib for architecture armv7 and in iOS Simulate mode: can't Load Simulate Framework! Pleeeasee Help me.. im stucked for days.. i see no such a .dylib in my mac folder and why simulate (more important this is) is not loading? Thank you. > {quote:ti...

Delphi XE5 iOS app orientation problem
I developed an iOS app using Delphi XE5, but when I run it on the simulator in landscape mode, and I try to open a web page with the instruction:      OpenURL ('http://www.google.it'); the device orientation automatically changes from landscape to portrait. Can anyone help me?. thanks ...

Uninstalling deployed PPB App
If our application is deployed onto a pocketPC, (dlls, executables, and database) and then run once or more times, the database, like on a desktop, becomes read-ony. When we try to do an uninstall through the Settings->Remove Programs for our application, we get an error message that it cannot be uninstalled because the database is read only. Do you know if any way I can modify my .INF file to build my deployable object so that it ignores this read-only flag, or am I going to have to do some quirky command to remove the read-only flag every time my application closes? If you ca...

renaming app breaks deployment of sqlite database
I finally had an app working with sqlite. I want to create an second app based on this first app. So i copied the whole structure to new directory. Then in projectmanager i renamed the app. Everything looks ok. Can even run it in the simulator. But when deploying it on an ipad i get again the frustration that the app cannot find the deployed database in the StartUp\Documents directory. The strange things is that when renaming the app back to the original name and run it it can start on the device. What setting should be changed in order to make an renamed app to work with docuemtns in S...

Firemonkey iOS app problem with resource files
I just started a new Firemonkey iOS app, and dropped a couple of TEdits and buttons on the main form along with a TMemo. When I try to build I get two error messages, for the dcc command line for the DPR: File not found: 'FMX_Filter.res' File not found: 'FMX_Platform_Win.res' Any ideas how to resolve those? I just wanted to compile the basic skeleton before moving on to add code to it. Thanks for your help! -- Cheers, Van "Half of what I say is meaningless..." - John Lennon "Your job is to figure out which half." - Van Swofford Ah, n...

Problem Linking C code in a Firemonkey iOS app
I am porting an App using XE2 (update 4) to iOS. It is a backgammon program (www.extremegammon.com) that relies on a neural network. The NN code is in C (I never got the time to convert it to pascal). I got the interface working well and very responsive (once i realized that using image effect such as shadow was something to absolutely avoid) and i am now adding the engine (about 60000 lines of Pascal and 4000 lines of C). i manage to compile it and it works well in the simulator (i386 architecture). the C code compiles for armv6 and armv7 (in a separate project). i copied the *.o files gen...

Web resources about - iOS FireDac sqlite database problem (when deployed with the app) - embarcadero.delphi.firemonkey

Database - Wikipedia, the free encyclopedia
... requiring information. For example, modelling the availability of rooms in hotels in a way that supports finding a hotel with vacancies. Database ...

Database - Wikipedia, the free encyclopedia
A database is an organized collection of data . The data are typically organized to model aspects of reality in a way that supports processes ...

Dodgy database exposes details of 191 million US voters
... years, there's a high chance that your personal details are now out in the wild. Security researcher Chris Vickery found a misconfigured database ...

3.3 million Hello Kitty fans' details have been exposed in a huge database leak
... week after week, the hacks, breaches and data leaks continue to roll in. The latest victim? Hello Kitty. CSO Online is reporting that a database ...

Under pressure, DNC restores Bernie Sanders campaign's access to their database - Videos - CBS News
A strange twist in the race for the democratic presidential nomination: the campaign of Vermont Senator Bernie Sanders has filed a complaint ...

Massive Voter Database Left Open For Public Consumption
Gosh, we could have avoided all the angst about the Clinton/Sanders voter database breach if only we'd known about this major database , accessible ...

Database configuration issues expose 191 million voter records
A misconfigured database has led to the disclosure of 191 million voter records. The database, discovered by researcher Chris Vickery, doesn't ...

Database error publishes data of 3 million Hello Kitty fans
Online researcher Chris Vickery uncovered a database this weekend containing the personal information of 3.3 million accounts associated with ...

191 Million US Voter Registration Records Leaked In Mystery Database
A huge database of 191 million US citizens is uncovered. But no one knows who carelessly left it open, whilst the FBI have been contacted.

Sanders campaign regains access to DNC voter database
Sanders campaign regains access to DNC voter database

Resources last updated: 12/30/2015 8:24:26 PM