Recent

Author Topic: SQLite Console Application  (Read 4825 times)

Kyshuo Ayame

  • Newbie
  • Posts: 2
SQLite Console Application
« on: September 03, 2015, 07:06:10 pm »
I need to create a console application in pascal that is capable of using a SQLite database. I only managed to do so by Forms, but not by console. To use the same code used by Forms throws the exception 'External: SIGSEGV'.

I do not need to use windows in my application, should be console. How I can connect to SQLite3 by simply source code? Is not there something similar to the used in Java or C ++?

Thank you.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: SQLite Console Application
« Reply #1 on: September 03, 2015, 07:31:40 pm »
What you can do by GUI can be done in console, too. SQLdb, despite having droppable components, are usable in non-GUI environment. A snippet from my lib:
Code: [Select]
uses
  db, sqldb, sqlite3conn;
var
  Conn: TSQLConnector;
  Trans: TSQLTransaction;
  Query: TSQLQuery;
begin
  Conn := TSQLConnector.Create(nil);
  with Conn do begin
    ConnectorType := 'SQLite3';
    HostName := ''; // not important
    DatabaseName := '/path/to/sqlite/db/file';
    UserName := ''; // not important
    Password := ''; // not important
  end;

  Trans := TSQLTransaction.Create(nil);
  Conn.Transaction := Trans;

  Query := TSQLQuery.Create(nil);
  Query.DataBase := Conn;
  Query.SQL.Text := 'insert your sql query here';
  // Query.ParamByName('...').AsWhatever := ... fill if you use parameterized query
  Query.ExecSQL; // or Query.Open; depending whether your query is select or not
 
  // for select query
  // while not Query.EOF do begin
  // do whatever you want, access row field with Query.FieldByName('...').AsWhatever
  //   Query.Next;
  // end;
  // Query.Close;

  // for non-select
  Trans.Commit;
end.
I use TSQLConnector for easy switching between supported connections, nothing stops you from directly using TSQLite3Connection.
Direct SQLite API calls are also possible (see packages/sqlite/tests for sample programs).
« Last Edit: September 03, 2015, 07:33:11 pm by Leledumbo »

Kyshuo Ayame

  • Newbie
  • Posts: 2
Re: SQLite Console Application
« Reply #2 on: September 03, 2015, 09:31:42 pm »
Thank you!!!!!!! You are a genious!!!! It worked very well.

¿Have you got any material that could recommend the use of SELECT statements, INSERT and UPDATE? I researched a lot on the Web and there is nothing useful. Only when I posted the question here I could fix the problem.

Many thanks.

 

TinyPortal © 2005-2018