Recent

Author Topic: LAMW: Where does save myData.db in SQLite ?  (Read 5975 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
LAMW: Where does save myData.db in SQLite ?
« on: January 31, 2017, 12:25:39 pm »
hi
i use "AppSqliteDemo1".
Where does save myData.db in SQLite ?
------------------------
jSqliteDataAccess1.OpenOrCreate(jSqliteDataAccess1.DataBaseName);  // myData.db
« Last Edit: January 31, 2017, 06:43:54 pm by majid.ebru »

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #1 on: January 31, 2017, 07:44:38 pm »
This code will create/open 'myData.db' in internal app storage ["...../file/database"]
Code: Pascal  [Select][+][-]
  1.     jSqliteDataAccess1.OpenOrCreate(jSqliteDataAccess1.DataBaseName);  // myData.db
  2.  

You can test/find the path with this code:
 
Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. var
  3.   pathToDB: string;
  4. begin
  5.    pathToDB:=Self.GetEnvironmentDirectoryPath(dirDatabase);
  6.    ShowMessage(pathToDB);
  7.  
  8.     //copy   'myData.db' to directory download
  9.     Self.CopyFile(pathToDB + '/' + 'myData.db' , Self.GetEnvironmentDirectoryPath(dirDownloads) + '/' + 'myData.db');      
  10. end;
  11.  
« Last Edit: January 31, 2017, 07:53:09 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #2 on: February 02, 2017, 06:20:02 am »
this code worked.
thank you

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. var
  3.   pathToDB: string;
  4. begin
  5.    pathToDB:=Self.GetEnvironmentDirectoryPath(dirDatabase);
  6.    ShowMessage(pathToDB);
  7.  
  8.     //copy   'myData.db' to directory download
  9.     Self.CopyFile(pathToDB + '/' + 'myData.db' , Self.GetEnvironmentDirectoryPath(dirDownloads) + '/' + 'myData.db');      
  10. end;
  11.  

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #3 on: February 02, 2017, 06:21:51 am »
how can i just open file ( myDate.db)?
or
how can i just Create file ( myDate.db)?
or
how can i control that file is exist?


This code will create/open 'myData.db' in internal app storage ["...../file/database"]
Code: Pascal  [Select][+][-]
  1.     jSqliteDataAccess1.OpenOrCreate(jSqliteDataAccess1.DataBaseName);  // myData.db
  2.  

Handoko

  • Hero Member
  • *****
  • Posts: 5153
  • My goal: build my own game engine using Lazarus
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #4 on: February 02, 2017, 06:57:22 am »
I'm not good about it. But I think you maybe will be interested to see the example codes of using Sqlite on LAMW:

[your_lamw_directory]\trunk\demos\Eclipse\AppSqliteDemo1

[your_lamw_directory]\trunk\demos\Eclipse\AppSqliteDemo2

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #5 on: February 03, 2017, 01:50:51 am »

Please, try:

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. var
  3.   dbExists: boolean;
  4. begin
  5.    dbExists:= jSqliteDataAccess1.CheckDataBaseExistsByName('myData.db');
  6.    if  dbExists = True then
  7.       ShowMessage('Data Base Exists!')
  8.    else
  9.       ShowMessage('Sorry... Data Base Not Found...');
  10. end;
  11.  
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

FerCastro

  • New member
  • *
  • Posts: 8
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #6 on: April 23, 2017, 09:54:14 pm »
Hello

I am trying to open/create the database on the OnCreate method but when I try this my app hangs.

I am trying to create my database, and the access to my data with my app. Is it possible open/create the database but not with a button?

Thanks in advance


FerCastro

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #7 on: April 23, 2017, 10:03:50 pm »

Hello  FerCastro!

The "OnCreate" handle only pascal code initialization....

Use "OnJINPrompt" to init all android stuff ....
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

FerCastro

  • New member
  • *
  • Posts: 8
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #8 on: April 25, 2017, 09:01:43 pm »
Hello jmpessoa, and thanks a lot for Your help.

I am trying to create an app that uses a salite database, but without buttons to create/open database/tabes

Actually I use your code of the SQLite Demo 1 in order to crate the objects. As you suggested in your last post, I use the OnJNIPrompt Method to invoke the creation of database and table, but when i run in my mobile I never get the last showmessage.

I attach one image of the message window.

Is there something I am missing?

Regards!!

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.OnJNIPrompt(Sender: TObject);
  2. begin
  3.   Access.OpenOrCreate('Data.db');
  4.   Access.CreateTable('CREATE TABLE IF  NOT EXISTS '+ FTableName +'(_ID INTEGER PRIMARY KEY AUTOINCREMENT, TITLE   TEXT,AUTHOR TEXT, COUNT INTEGER, FIGURE BLOB);');
  5.   ShowMessage('table created!');
  6. end;    
  7.  

jmpessoa

  • Hero Member
  • *****
  • Posts: 2301
Re: LAMW: Where does save myData.db in SQLite ?
« Reply #9 on: April 25, 2017, 09:43:44 pm »

Hello Fer!

This "ShowMessage" is too fast!   [android "Toast"]

try:

gApp.ShowMessage()....     [more like Lazarus ....]

Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018