Jump to content
Robert Gilland

Android Create SQLLite Database at Runtime.

Recommended Posts

Do you have permissions to write the DB?
Did you try to write a test file like "test.txt"? If it doesn't work, you don't have write permissions.

Otherwise please provide the error message (if any) you get when creating the DB

  • Like 1

Share this post


Link to post

Victory:

 

I created an empty file fist by this method and then all good:

 

  lsDBPath := DBPath;
  if( not FileExists(lsDBPAth))then
    begin
      lhandle := System.SysUtils.FileCreate(lsDBPath);
      System.SysUtils.FileClose(lhandle);
    end;

  cnctnDB.Params.Values['Database'] := lsDBPath;
  cnctnDB.Params.Values['SQLiteAdvanced'] := 'page_size=4096';
  cnctnDB.Params.Values['OpenMode'] := 'ReadWrite';

Share this post


Link to post

Hi @Robert Gilland

Can you give us the code you used previously ? It's very strange you need to create a file before using it as a SQLite database. I've never needed to do that.

Perhaps you need some permission about external storage or use a not authorized folder ?

Share this post


Link to post

Previous code was

 

procedure Tdtmdl.CheckDatabaseExists;
var
  EmptyDB: string;
begin
  if not FileExists(DBPath) then
  begin
    EmptyDB := DocumentsFolderPath + 'empty.sqlite';
    TFile.Copy(EmptyDB, DBPath);
  end;
end;

procedure Tdtmdl.ConfigureDatabaseAndTable;
var
  SQL: string;
  SL: TStringList;
begin
//  if fActiveApp = TActiveApp.aaNone then exit;

  cnctnDB.Params.Values['Database'] := DBPath;

  CheckDatabaseExists;

  try
    cnctnDB.Connected := true;
  except
    on e:Exception do
    begin
    end;
  end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×