Recent

Author Topic: Install and use a SQLite database  (Read 8526 times)

mmvisual

  • New Member
  • *
  • Posts: 19
Install and use a SQLite database
« on: January 07, 2007, 04:05:39 pm »
Hello,

I'm a beginner with Lazarus. I want develope a new application for Linux and windows. I think Windows is the smaller problen, so I want build de application in Linux with Lazarus.

I have install Lazarus, and I can make a new projekt with a button, compile and start. Ok it's a very simple test.

Now I want use a SQLite database in my application.

Here begin my problems:
I need a step by step help how I can make a database connection.
- Witch component can I use (from Lazarus-folder? / URL?)
- How I include this units
- How I include the file "sqlite3.so"
- The resolution must be a functional program without any bugs
- other requirements (rpm's from Linux system??)
- I use Databases in Delphi and I know TDataSet/TDatasource/TDBxxx-components

Thank you very much, Markus

mmvisual

  • New Member
  • *
  • Posts: 19
RE: Install and use a SQLite database
« Reply #1 on: January 07, 2007, 09:32:23 pm »
I have found it, I post the complete project ... i hope it is usefully for you.

I use this system now:
- Suse Linux 10.2
- FPC2.0.4
- Lazarus 0.9.20
- SQLite 3.3.9
- Include the Units "/usr/lib/lazarus/components/sqlite/""
- All is now the newest...

File "project1.lpr"
Code: [Select]

program project1;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms
  { add your units here }, fmain;

begin
  Application.Initialize;
  Application.CreateForm(TfrmMain, frmMain);
  Application.Run;
end.

File "project1.lpi"
Code: [Select]

<?xml version="1.0"?>
<CONFIG>
  <ProjectOptions>
    <PathDelim Value="/"/>
    <Version Value="5"/>
    <General>
      <MainUnit Value="0"/>
      <IconPath Value="./"/>
      <TargetFileExt Value=""/>
      <ActiveEditorIndexAtStart Value="1"/>
    </General>
    <VersionInfo>
      <ProjectVersion Value=""/>
      <Language Value="0407"/>
    </VersionInfo>
    <PublishOptions>
      <Version Value="2"/>
      <IgnoreBinaries Value="False"/>
      <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
      <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
    </PublishOptions>
    <RunParams>
      <local>
        <FormatVersion Value="1"/>
        <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
      </local>
    </RunParams>
    <RequiredPackages Count="2">
      <Item1>
        <PackageName Value="LCL"/>
      </Item1>
      <Item2>
        <PackageName Value="FCL"/>
        <MinVersion Major="1" Valid="True"/>
      </Item2>
    </RequiredPackages>
    <Units Count="42">
      <Unit0>
        <Filename Value="project1.lpr"/>
        <IsPartOfProject Value="True"/>
        <UnitName Value="project1"/>
        <CursorPos X="1" Y="4"/>
        <TopLine Value="1"/>
        <EditorIndex Value="0"/>
        <UsageCount Value="56"/>
        <Loaded Value="True"/>
      </Unit0>
      <Unit1>
        <Filename Value="fmain.pas"/>
        <ComponentName Value="frmMain"/>
        <IsPartOfProject Value="True"/>
        <ResourceFilename Value="fmain.lrs"/>
        <UnitName Value="fmain"/>
        <CursorPos X="4" Y="123"/>
        <TopLine Value="94"/>
        <EditorIndex Value="1"/>
        <UsageCount Value="56"/>
        <Loaded Value="True"/>
      </Unit1>
      <Unit2>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/asqlite3.dpk"/>
        <UnitName Value="asqlite3"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="8"/>
      </Unit2>
      <Unit3>
        <Filename Value="/usr/lib/lazarus/components/rx/rx.pas"/>
        <UnitName Value="rx"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="8"/>
      </Unit3>
      <Unit4>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/asqlitepkg3D5.dpk"/>
        <UnitName Value="asqlite3pkgD5"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="9"/>
        <UsageCount Value="8"/>
      </Unit4>
      <Unit5>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/asqlite3D5.dpk"/>
        <UnitName Value="asqlite3D5"/>
        <CursorPos X="62" Y="14"/>
        <TopLine Value="9"/>
        <UsageCount Value="9"/>
      </Unit5>
      <Unit6>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/ASGSQLite3Dsg.pas"/>
        <UnitName Value="ASGSQLite3Dsg"/>
        <CursorPos X="16" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="20"/>
      </Unit6>
      <Unit7>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/asqlite3.pas"/>
        <UnitName Value="asqlite3"/>
        <CursorPos X="8" Y="10"/>
        <TopLine Value="1"/>
        <UsageCount Value="9"/>
      </Unit7>
      <Unit8>
        <Filename Value="/usr/lib/lazarus/components/sqldb/registersqldb.lrs"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="414"/>
        <UsageCount Value="8"/>
      </Unit8>
      <Unit9>
        <Filename Value="/usr/lib/lazarus/components/sqldb/sqldblaz.pas"/>
        <UnitName Value="SQLDBLaz"/>
        <CursorPos X="58" Y="17"/>
        <TopLine Value="1"/>
        <UsageCount Value="8"/>
      </Unit9>
      <Unit10>
        <Filename Value="/usr/lib/lazarus/packager/registration/lazaruspackageintf.pas"/>
        <UnitName Value="LazarusPackageIntf"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="8"/>
      </Unit10>
      <Unit11>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/asqlite_def.inc"/>
        <CursorPos X="12" Y="69"/>
        <TopLine Value="59"/>
        <UsageCount Value="19"/>
      </Unit11>
      <Unit12>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/AMDSqlite3.pas"/>
        <UnitName Value="AMDSqlite3"/>
        <CursorPos X="1" Y="2"/>
        <TopLine Value="1"/>
        <UsageCount Value="19"/>
      </Unit12>
      <Unit13>
        <Filename Value="/usr/lib/lazarus/lcl/forms.pp"/>
        <UnitName Value="Forms"/>
        <CursorPos X="37" Y="138"/>
        <TopLine Value="123"/>
        <UsageCount Value="8"/>
      </Unit13>
      <Unit14>
        <Filename Value="/usr/lib/lazarus/lcl/controls.pp"/>
        <UnitName Value="Controls"/>
        <CursorPos X="29" Y="769"/>
        <TopLine Value="754"/>
        <UsageCount Value="8"/>
      </Unit14>
      <Unit15>
        <Filename Value="/usr/lib/lazarus/lcl/lclclasses.pp"/>
        <UnitName Value="LCLClasses"/>
        <CursorPos X="31" Y="38"/>
        <TopLine Value="23"/>
        <UsageCount Value="8"/>
      </Unit15>
      <Unit16>
        <Filename Value="/usr/share/fpcsrc/rtl/objpas/classes/classesh.inc"/>
        <CursorPos X="27" Y="295"/>
        <TopLine Value="280"/>
        <UsageCount Value="8"/>
      </Unit16>
      <Unit17>
        <Filename Value="/usr/share/fpcsrc/rtl/inc/objpash.inc"/>
        <CursorPos X="8" Y="116"/>
        <TopLine Value="101"/>
        <UsageCount Value="8"/>
      </Unit17>
      <Unit18>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/ASGSQLite3.pas"/>
        <UnitName Value="ASGSQLite3"/>
        <CursorPos X="11" Y="2026"/>
        <TopLine Value="2008"/>
        <UsageCount Value="19"/>
      </Unit18>
      <Unit19>
        <Filename Value="/usr/lib/lazarus/components/asqlite3/ASGRout3.pas"/>
        <UnitName Value="ASGRout3"/>
        <CursorPos X="1" Y="200"/>
        <TopLine Value="185"/>
        <UsageCount Value="19"/>
      </Unit19>
      <Unit20>
        <Filename Value="/usr/share/fpcsrc/fcl/db/db.pp"/>
        <UnitName Value="db"/>
        <CursorPos X="7" Y="2206"/>
        <TopLine Value="2175"/>
        <UsageCount Value="10"/>
      </Unit20>
      <Unit21>
        <Filename Value="/usr/share/fpcsrc/fcl/db/sqlite/sqlite3ds.pas"/>
        <UnitName Value="sqlite3ds"/>
        <CursorPos X="39" Y="36"/>
        <TopLine Value="17"/>
        <UsageCount Value="11"/>
      </Unit21>
      <Unit22>
        <Filename Value="/usr/lib/lazarus/components/sqlite/registersqlite3.pas"/>
        <UnitName Value="registersqlite3"/>
        <CursorPos X="1" Y="10"/>
        <TopLine Value="7"/>
        <UsageCount Value="10"/>
      </Unit22>
      <Unit23>
        <Filename Value="/usr/lib/lazarus/components/sqlite/sqlitecomponenteditor.pas"/>
        <ComponentName Value="SqliteTableEditorForm"/>
        <HasResources Value="True"/>
        <UnitName Value="SqliteComponentEditor"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit23>
      <Unit24>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/sqlcomponents.pas"/>
        <UnitName Value="sqlcomponents"/>
        <CursorPos X="1" Y="11"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit24>
      <Unit25>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/passqlite.pas"/>
        <UnitName Value="passqlite"/>
        <CursorPos X="9" Y="46"/>
        <TopLine Value="15"/>
        <UsageCount Value="10"/>
      </Unit25>
      <Unit26>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/demo/simple console demo/consoledemo.dpr"/>
        <UnitName Value="consoledemo"/>
        <CursorPos X="43" Y="9"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit26>
      <Unit27>
        <Filename Value="/usr/lib/lazarus/lcl/lresources.pp"/>
        <UnitName Value="LResources"/>
        <CursorPos X="32" Y="31"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit27>
      <Unit28>
        <Filename Value="/usr/lib/lazarus/lcl/extctrls.pp"/>
        <UnitName Value="ExtCtrls"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit28>
      <Unit29>
        <Filename Value="/usr/lib/lazarus/lcl/stdctrls.pp"/>
        <UnitName Value="StdCtrls"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit29>
      <Unit30>
        <Filename Value="/usr/lib/lazarus/lcl/dbgrids.pas"/>
        <UnitName Value="DBGrids"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit30>
      <Unit31>
        <Filename Value="/tmp/testcompileroptions.pas"/>
        <UnitName Value="testcompileroptions"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit31>
      <Unit32>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/libsqlite.pas"/>
        <UnitName Value="libsqlite"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit32>
      <Unit33>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/pasjansql.pas"/>
        <UnitName Value="pasjansql"/>
        <CursorPos X="6" Y="28"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit33>
      <Unit34>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/jansql/janSQL.pas"/>
        <UnitName Value="janSQL"/>
        <CursorPos X="1" Y="51"/>
        <TopLine Value="27"/>
        <UsageCount Value="10"/>
      </Unit34>
      <Unit35>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/passql.pas"/>
        <UnitName Value="passql"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit35>
      <Unit36>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/ASyncDB.pas"/>
        <UnitName Value="ASyncDB"/>
        <CursorPos X="21" Y="21"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit36>
      <Unit37>
        <Filename Value="/usr/lib/lazarus/components/sqlite3/jansql/janSQLstrings.pas"/>
        <UnitName Value="janSQLStrings"/>
        <CursorPos X="1" Y="105"/>
        <TopLine Value="87"/>
        <UsageCount Value="10"/>
      </Unit37>
      <Unit38>
        <Filename Value="/usr/share/fpcsrc/fcl/db/sqlite/customsqliteds.pas"/>
        <UnitName Value="customsqliteds"/>
        <CursorPos X="20" Y="213"/>
        <TopLine Value="197"/>
        <UsageCount Value="11"/>
      </Unit38>
      <Unit39>
        <Filename Value="/usr/share/fpcsrc/packages/base/sqlite/sqlite3.pp"/>
        <UnitName Value="sqlite3"/>
        <CursorPos X="1" Y="1"/>
        <TopLine Value="3"/>
        <UsageCount Value="11"/>
      </Unit39>
      <Unit40>
        <Filename Value="/usr/share/fpcsrc/rtl/objpas/sysutils/sysstrh.inc"/>
        <CursorPos X="18" Y="75"/>
        <TopLine Value="1"/>
        <UsageCount Value="10"/>
      </Unit40>
      <Unit41>
        <Filename Value="/usr/share/fpcsrc/fcl/db/fields.inc"/>
        <CursorPos X="33" Y="928"/>
        <TopLine Value="909"/>
        <UsageCount Value="10"/>
      </Unit41>
    </Units>
    <JumpHistory Count="1" HistoryIndex="0">
      <Position1>
        <Filename Value="fmain.pas"/>
        <Caret Line="112" Column="32" TopLine="90"/>
      </Position1>
    </JumpHistory>
  </ProjectOptions>
  <CompilerOptions>
    <Version Value="5"/>
    <SearchPaths>
      <OtherUnitFiles Value="/usr/lib/lazarus/components/sqlite/"/>
      <SrcPath Value="$(LazarusDir)/lcl/;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)/"/>
    </SearchPaths>
    <CodeGeneration>
      <Checks>
        <IOChecks Value="True"/>
        <RangeChecks Value="True"/>
        <OverflowChecks Value="True"/>
        <StackChecks Value="True"/>
      </Checks>
      <Generate Value="Faster"/>
    </CodeGeneration>
    <Linking>
      <Options>
        <Win32>
          <GraphicApplication Value="True"/>
        </Win32>
      </Options>
    </Linking>
    <Other>
      <Verbosity>
        <ShoLineNum Value="True"/>
      </Verbosity>
      <CompilerPath Value="$(CompPath)"/>
    </Other>
  </CompilerOptions>
  <Debugging>
    <Exceptions Count="2">
      <Item1>
        <Name Value="ECodetoolError"/>
      </Item1>
      <Item2>
        <Name Value="EFOpenError"/>
      </Item2>
    </Exceptions>
  </Debugging>
</CONFIG>

mmvisual

  • New Member
  • *
  • Posts: 19
RE: Install and use a SQLite database
« Reply #2 on: January 07, 2007, 09:36:37 pm »
The next code...

File "fmain.pas"
Code: [Select]

unit fmain;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}

interface

uses
  {$IFDEF WIN32}
  Windows,
  {$ELSE}
  Libc,
  {$ENDIF}
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
  Buttons, StdCtrls, ExtCtrls,
  DBGrids, DB,
  sqlite3ds;

type

  { TfrmMain }

  TfrmMain = class(TForm)
    btnExecSQL: TButton;
    btnShowTable: TButton;
    dsTest: TDatasource;
    grdTest: TDBGrid;
    lstOld: TListBox;
    edSQL: TMemo;
    Panel1: TPanel;
    Splitter1: TSplitter;
    procedure btnExecSQLClick(Sender: TObject);
    Procedure FormCreate(Sender: TObject);
    Procedure FormDestroy(Sender: TObject);
    Procedure btnShowTableClick(Sender: TObject);
    Procedure lstOldDblClick(Sender: TObject);
  private
    { private declarations }
    qryTest: TSqlite3Dataset;
  public
    { public declarations }
    Procedure qryTestAfterOpen(DataSet: TDataSet);
  end;

var
  frmMain: TfrmMain;

implementation

{ TfrmMain }

procedure TfrmMain.btnExecSQLClick(Sender: TObject);
Var
  i: Integer;
  bExec: Boolean;
  sSQL: String;
begin
  sSQL := StringReplace(edSQL.Text, #10, ' ', [rfReplaceAll]);
  sSQL := StringReplace(sSQL, #13, ' ', [rfReplaceAll]);
  sSQL := StringReplace(sSQL, '', ' ', [rfReplaceAll]);
  For i := 0 To lstOld.Items.Count - 1 Do
  Begin // Delete all old same query's from list
    If SameText(lstOld.Items.Strings[i], sSQL) Then
    Begin
      lstOld.Items.Delete(i);
      Break;
    End;
  End;
  bExec := Not(Pos('SELECT', UpperCase(sSQL)) = 1); // Query for Execution?
  If bExec Then
    lstOld.Items.Insert(0, 'Exec: ' + sSQL) // Log Query
  Else lstOld.Items.Insert(0, sSQL);
  qryTest.Close;
  If bExec Then
    qryTest.ExecSQL(sSQL) // Exec Query
  Else Begin
    qryTest.SQL := sSQL; // Open SELECT Query
    qryTest.Open;
  End;
end;

Procedure TfrmMain.FormCreate(Sender: TObject);
Begin
  qryTest := TSqlite3Dataset.Create(Nil);
  dsTest.DataSet := qryTest;
  qryTest.FileName := 'Test.db';
  qryTest.AfterOpen := @qryTestAfterOpen;
  btnShowTableClick(Nil);
end;

Procedure TfrmMain.FormDestroy(Sender: TObject);
Begin
  dsTest.DataSet := Nil;
  qryTest.Free;
end;

Procedure TfrmMain.btnShowTableClick(Sender: TObject);
Begin
  // Text for query all existing table names in database
  edSQL.Text := 'SELECT tbl_name FROM (SELECT * FROM sqlite_master UNION ' +
                'ALL SELECT * FROM sqlite_temp_master) WHERE type!=''meta''' +
                'ORDER BY type DESC, name';
  If Sender <> Nil Then
     btnExecSQLClick(Nil);
end;

Procedure TfrmMain.lstOldDblClick(Sender: TObject);
Begin
  If lstOld.ItemIndex < 0 Then Exit;
  If lstOld.Items.Count <= 0 Then Exit;
  edSQL.Text := lstOld.Items[lstOld.ItemIndex];
  If Pos('Exec: ', edSQL.Text) = 1 Then
     edSQL.Text := Copy(edSQL.Text, 7, Length(edSQL.Text) - 7);
end;

Procedure TfrmMain.qryTestAfterOpen(DataSet: TDataSet);
Var i: Integer;
Begin
  For i := 0 To (DataSet.FieldCount - 1) Do
  Begin // Set Displaywidth for String fields
    If DataSet.Fields[i].DataType = ftString Then
    Begin
      // This is now a bug from FPC:
      //DataSet.Fields[i].DisplayWidth := 15’;
    End;
  End;
End;

initialization
  {$I fmain.lrs}

end.

mmvisual

  • New Member
  • *
  • Posts: 19
RE: Install and use a SQLite database
« Reply #3 on: January 07, 2007, 09:38:15 pm »
The next code...

File "fmain.lfm"
Code: [Select]

object frmMain: TfrmMain
  Left = 242
  Height = 381
  Top = 137
  Width = 524
  HorzScrollBar.Page = 523
  VertScrollBar.Page = 380
  ActiveControl = btnExecSQL
  Caption = 'frmMain'
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  object Panel1: TPanel
    Height = 96
    Width = 524
    Align = alTop
    BevelOuter = bvNone
    TabOrder = 0
    object btnExecSQL: TButton
      Left = 446
      Height = 25
      Top = 22
      Width = 75
      Anchors = [akTop, akRight]
      BorderSpacing.InnerBorder = 4
      Caption = 'ExecSQL'
      OnClick = btnExecSQLClick
      TabOrder = 0
    end
    object btnShowTable: TButton
      Height = 17
      Width = 112
      BorderSpacing.InnerBorder = 4
      Caption = 'ShowTable'
      OnClick = btnShowTableClick
      TabOrder = 1
    end
    object edSQL: TMemo
      Left = 1
      Height = 64
      Top = 25
      Width = 440
      Anchors = [akTop, akLeft, akRight]
      Lines.Strings = (
        ''
      )
      ScrollBars = ssAutoBoth
      TabOrder = 2
    end
  end
  object Splitter1: TSplitter
    Cursor = crVSplit
    Height = 6
    Top = 152
    Width = 524
    Align = alTop
    Color = clBlack
    ParentColor = False
    ResizeAnchor = akTop
  end
  object grdTest: TDBGrid
    Height = 223
    Top = 158
    Width = 524
    Align = alClient
    DataSource = dsTest
    FixedColor = clBtnFace
    Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColumnMove, dgColLines, dgRowLines, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit]
    OptionsExtra = [dgeAutoColumns, dgeCheckboxColumn]
    ParentColor = False
    TabOrder = 1
    TabStop = True
  end
  object lstOld: TListBox
    Height = 56
    Top = 96
    Width = 524
    Align = alTop
    OnDblClick = lstOldDblClick
    TabOrder = 2
    TopIndex = -1
  end
  object dsTest: TDatasource
    left = 137
    top = 67
  end
end

mmvisual

  • New Member
  • *
  • Posts: 19
RE: Install and use a SQLite database
« Reply #4 on: January 07, 2007, 09:39:39 pm »
The last file...

File "fmain.lrs"
Code: [Select]

LazarusResources.Add('TfrmMain','FORMDATA',[
  'TPF0'#8'TfrmMain'#7'frmMain'#4'Left'#3#242#0#6'Height'#3'}'#1#3'Top'#3#137#0
  +#5'Width'#3#12#2#18'HorzScrollBar.Page'#3#11#2#18'VertScrollBar.Page'#3'|'#1
  +#13'ActiveControl'#7#10'btnExecSQL'#7'Caption'#6#7'frmMain'#8'OnCreate'#7#10
  +'FormCreate'#9'OnDestroy'#7#11'FormDestroy'#0#6'TPanel'#6'Panel1'#6'Height'#2
  +'`'#5'Width'#3#12#2#5'Align'#7#5'alTop'#10'BevelOuter'#7#6'bvNone'#8'TabOrde'
  +'r'#2#0#0#7'TButton'#10'btnExecSQL'#4'Left'#3#190#1#6'Height'#2#25#3'Top'#2
  +#22#5'Width'#2'K'#7'Anchors'#11#5'akTop'#7'akRight'#0#25'BorderSpacing.Inner'
  +'Border'#2#4#7'Caption'#6#7'ExecSQL'#7'OnClick'#7#15'btnExecSQLClick'#8'TabO'
  +'rder'#2#0#0#0#7'TButton'#12'btnShowTable'#6'Height'#2#17#5'Width'#2'p'#25'B'
  +'orderSpacing.InnerBorder'#2#4#7'Caption'#6#9'ShowTable'#7'OnClick'#7#17'btn'
  +'ShowTableClick'#8'TabOrder'#2#1#0#0#5'TMemo'#5'edSQL'#4'Left'#2#1#6'Height'
  +#2'@'#3'Top'#2#25#5'Width'#3#184#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRigh'
  +'t'#0#13'Lines.Strings'#1#6#0#0#10'ScrollBars'#7#10'ssAutoBoth'#8'TabOrder'#2
  +#2#0#0#0#9'TSplitter'#9'Splitter1'#6'Cursor'#7#8'crVSplit'#6'Height'#2#6#3'T'
  +'op'#3#152#0#5'Width'#3#12#2#5'Align'#7#5'alTop'#5'Color'#7#7'clBlack'#11'Pa'
  +'rentColor'#8#12'ResizeAnchor'#7#5'akTop'#0#0#7'TDBGrid'#7'grdTest'#6'Height'
  +#3#223#0#3'Top'#3#158#0#5'Width'#3#12#2#5'Align'#7#8'alClient'#10'DataSource'
  +#7#6'dsTest'#10'FixedColor'#7#9'clBtnFace'#7'Options'#11#9'dgEditing'#8'dgTi'
  +'tles'#11'dgIndicator'#14'dgColumnResize'#12'dgColumnMove'#10'dgColLines'#10
  +'dgRowLines'#6'dgTabs'#21'dgAlwaysShowSelection'#15'dgConfirmDelete'#14'dgCa'
  +'ncelOnExit'#0#12'OptionsExtra'#11#14'dgeAutoColumns'#17'dgeCheckboxColumn'#0
  +#11'ParentColor'#8#8'TabOrder'#2#1#7'TabStop'#9#0#0#8'TListBox'#6'lstOld'#6
  +'Height'#2'8'#3'Top'#2'`'#5'Width'#3#12#2#5'Align'#7#5'alTop'#10'OnDblClick'
  +#7#14'lstOldDblClick'#8'TabOrder'#2#2#8'TopIndex'#2#255#0#0#11'TDatasource'#6
  +'dsTest'#4'left'#3#137#0#3'top'#2'C'#0#0#0
]);

mmvisual

  • New Member
  • *
  • Posts: 19
RE: Install and use a SQLite database
« Reply #5 on: January 07, 2007, 09:52:41 pm »
The description:

Copy the database library:
On next, copy the library "sqlite3.so" into the same folder from code and rename it into "sqlite3".
Compile and start the application with Lazarus.

The function:
- Memo-Text with you can type your SQL command
- Button to Execute the SQL
- List with the last commands
- TDBGrid with show the result
- Button with SQL Code for looking witch tabels exists in the database
- Button ShowTable type a SQL string into the memo who you can show all tabels in database

Start the Application:
- Type in the memo:
  CREATE TABEL testtbl (ID INTEGER, txt VARCHAR(100))
- Press the button
>> it create a automaticly a new database file "Test.db" and a table "testbl"
- Type in memo:
  SELECT * FROM testtbl
- Press the button
>> See a empty tabel in the Grid
- Type in memo:
  INSERT INTO testbl (ID, text) VALUES(3, 'gugus')
- Press the button
- double click in the list entry "SELECT * FROM testtbl"
- Press the button
>> See a empty tabel in the Grid with one entry

Known bugs:
- You cannot compile the line "DataSet.Fields[ i ].DisplayWidth := 15;" but the code is right.
- The Code "For i := 0 To lstOld.Items.Count - 1 Do" want seek and delete double entry from the list, but it do not work always good.
- Why this bugs are inside, I do not know...

Please test this code and write a feedback.

Have a lot of fun,
Markus. :D