* * *

Author Topic: How to create FireBird database from Lazarus  (Read 11433 times)

motaz

  • Sr. Member
  • ****
  • Posts: 385
    • http://code.sd
How to create FireBird database from Lazarus
« on: December 04, 2009, 09:51:40 am »
I need to create a new database from Lazarus application, the same like what I do using ISQL.
Thanks

clauslack

  • Sr. Member
  • ****
  • Posts: 271
Re: How to create FireBird database from Lazarus
« Reply #1 on: December 04, 2009, 01:43:13 pm »
In SQLDB, there is IBConnection1.CreateDb (Before fill user, password, etc)

I don't test this (I always use flamerobin)

Regards.

SteveF

  • Jr. Member
  • **
  • Posts: 92
Re: How to create FireBird database from Lazarus
« Reply #2 on: December 04, 2009, 10:52:18 pm »
Clauslack,

Where can I find documentation of the methods, properties, etc. for these controls?  Both what is actually available and the parameters needed for proper use?

Thanks,
Steve

clauslack

  • Sr. Member
  • ****
  • Posts: 271
Re: How to create FireBird database from Lazarus
« Reply #3 on: December 05, 2009, 02:06:45 am »
Quote
Where can I find documentation
I don't know, It is similar to TIBDatabase from Delphi. You can check the source code from sqldb too.

I test this simple example and work fine.

- Put an IBConnection1 in the form
Code: [Select]
procedure TForm1.Button1Click(Sender:TObject);
begin
IBConnection1.DatabaseName:='localhost:c:\prueba.fdb';
IBConnection1.UserName:='sysdba';
IBConnection1.Password:='masterkey';
IBConnection1.CreateDB;
end;
Tested with Lazarus 0.9.29 fpc 2.3.1, under Windows XP SP3 and Firebird SQL 2.1.3
- DatabaseAccess = Full in firebird.conf (you can use alias too).

Firebird 2.1.3 has this defaults
Database file ODS Version 11.1
Page size 4096
Page buffers 2048
Read only false
Dialect 3
Default character set NONE
Sweep interval 20000
Forced writes ON

For assign Charset(UTF8) you need fpc 2.3.1 svn>= 13386, see
http://bugs.freepascal.org/view.php?id=13835

Regards

« Last Edit: December 05, 2009, 02:08:20 am by clauslack »

motaz

  • Sr. Member
  • ****
  • Posts: 385
    • http://code.sd
Re: How to create FireBird database from Lazarus
« Reply #4 on: December 05, 2009, 08:26:21 am »
Thanks it works

asdf

  • Sr. Member
  • ****
  • Posts: 302
Re: How to create FireBird database from Lazarus
« Reply #5 on: October 20, 2010, 02:06:58 pm »
If I put the IBConnection1 into DataModule1, how should I refer Datamodule1 in this form?
O/S                    Windows XP
Lazarus Version   1.1
Date                   2012/09/27
FPC Version         2.6.1
SVN Revision        38849
i386-win32-win32/win64

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to create FireBird database from Lazarus
« Reply #6 on: October 20, 2010, 03:06:30 pm »
Your lazarus project [project1.lpr]
Quote
program project1;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Interfaces, // this includes the LCL widgetset
  Forms, Unit1, LResources, SQLDBLaz, Unit2
  { you can add units after this };

{$IFDEF WINDOWS}{$R project1.rc}{$ENDIF}

begin
  {$I project1.lrs}
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
//Application.CreateForm(TDataModule1, DataModule1);
  Application.Run;
end.



Your Datamodule [unit2]
Quote
unit Unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, IBConnection, sqldb, db, FileUtil, LResources, Forms,
  Controls, Dialogs;

type

  { TDataModule1 }

  TDataModule1 = class(TDataModule)
    Datasource1: TDatasource;
    IBConnection1: TIBConnection;
    SQLQuery1: TSQLQuery;
    SQLTransaction1: TSQLTransaction;
  private
    { private declarations }
  public
    { public declarations }

  end;


implementation

initialization
  {$I unit2.lrs}

end.



Your form1 [unit1]
Quote
unit Unit1;

{$mode objfpc}{$H+}

interface

uses Unit2,
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }

    //YOUR DATAMODULE
    MyMod: TDataModule1;


  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
        MyMod.IBConnection1.DatabaseName:='localhost:c:\prueba.fdb';
   MyMod.IBConnection1.UserName:='sysdba';
   MyMod.IBConnection1.Password:='masterkey';

        MyMod.SQLTransaction1.DataBase := MyMod.IBConnection1;
   MyMod.IBConnection1.Transaction := MyMod.SQLTransaction1;

        MyMod.SQLQuery1.DataBase := MyMod.IBConnection1;
        MyMod.SQLQuery1.Transaction := MyMod.SQLTransaction1;
        MyMod.SQLQuery1.SQL.Text := 'select * from yourtable';

        MyMod.SQLQuery1.Open;
end;

initialization
  {$I unit1.lrs}

end. 

 :D

asdf

  • Sr. Member
  • ****
  • Posts: 302
Re: How to create FireBird database from Lazarus
« Reply #7 on: October 20, 2010, 04:05:10 pm »
In DataModule

I have:

var
  DataModule1: TDataModule1;


implementation   

Do I have to delete "DataModule1: TDataModule1;" ?         
O/S                    Windows XP
Lazarus Version   1.1
Date                   2012/09/27
FPC Version         2.6.1
SVN Revision        38849
i386-win32-win32/win64

asdf

  • Sr. Member
  • ****
  • Posts: 302
Re: How to create FireBird database from Lazarus
« Reply #8 on: October 20, 2010, 05:07:16 pm »
Got error messase at:

MyMod: TDataModule1;

Identifier not found " TDataModule1 "
O/S                    Windows XP
Lazarus Version   1.1
Date                   2012/09/27
FPC Version         2.6.1
SVN Revision        38849
i386-win32-win32/win64

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to create FireBird database from Lazarus
« Reply #9 on: October 21, 2010, 01:08:20 am »
Quote
Got error messase at:

MyMod: TDataModule1;

Identifier not found " TDataModule1 "



uses Unit2,
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls;
« Last Edit: October 21, 2010, 01:14:46 am by xenablaise »

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to create FireBird database from Lazarus
« Reply #10 on: October 21, 2010, 01:10:54 am »
Quote
Do I have to delete "DataModule1: TDataModule1;" ? 

You dont need to, so you
would not delete or comment
//Application.CreateForm(TDataModule1, DataModule1);


xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to create FireBird database from Lazarus
« Reply #11 on: October 21, 2010, 01:20:40 am »
rsdb := TSQLQuery.Create(nil);
Quote
why use datamodules while you can directly call them
just like in vb6

cndb := TODBCConnection.Create(nil);
stran := TSQLTransaction.Create(nil);

stran.DataBase := cndb;
stran.Action := caCommit;
stran.Active := True;

cndb.Transaction := stran;
cndb.Open;

rsdb.DataBase := cndb;
rsdb.SQL.Text := 'SELECT * FROM Table1';
rsdb.Open;


Quote
my another sample



  TDBClass = class
  private

    // a data set to mantain all templates of database
    dsQuery: TSQLQuery;

    // the connection object
    mycon: TMYSQL40Connection;

    // SQL Transaction
    SQLTransact: TSQLTransaction;

  public
    function openDB(): boolean;
    procedure closeDB();
    procedure clearDB();

  end;

implementation
...
...
...

//TdbClass Usage
// Open connection
function TDBClass.openDB(): boolean;
begin
  try
        dsQuery := TSQLQuery.Create(nil);
        mycon := TMySQL40Connection.Create(nil);
        SQLTransact := TSQLTransaction.Create(nil);

        mycon.UserName := 'root';
        mycon.HostName := 'localhost';
        mycon.port := 3306;
        mycon.DatabaseName := 'XXX';

        SQLTransact.DataBase := mycon;
        SQLTransact.Action := caCommit;
        SQLTransact.Active := True;

        dsQuery.DataBase := mycon;

        mycon.Transaction := SQLTransact;
        mycon.Open;

       openDB := true;
  except
        openDB := false;
  end;
end;
 :D

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: How to create FireBird database from Lazarus
« Reply #12 on: October 23, 2010, 11:43:34 am »
Quote
WHAT SHOULD I DELETE MORE TO MAKE IT FIT?
:o

Quote
procedure TForm1.Button1Click(Sender: TObject);
begin
  rsdb := TSQLQuery.Create(nil);
  cndb := TIBConnection.Create(nil);
  trdb := TSQLTransaction.Create(nil);

  cndb.DatabaseName:= 'c:\test005.fdb';
  cndb.UserName:= 'sysdba';
  cndb.Password:= 'masterkey';
  cndb.CreateDB;

  trdb.DataBase := cndb;
  trdb.Action := caCommit;
  trdb.Active := True;

  rsdb.database := cndb;
  rsdb.sql.text := 'select * from table1';
  rsdb.open;


end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  close
end;

//saving
procedure TForm1.Button3Click(Sender: TObject);
begin
if Button3.caption := 'new' then
begin
rsdb.insert;
Button3.caption := 'save';
end
else
begin

if (dbedit1.text= '') or (dbedit1.text='') then
begin
//
end
else
begin
rsdb.post;
rsdb.applyupdates;
trdb.commitretainning;
end;

Button3.caption := 'new';
end;

end;


asdf?
Have you visited my sqlite sample code project?
it has the ability to add, delete, update records.
you just have to change a little if you want to change from sqlite to firebird.
please see the codes, so you can determined how tos.
http://wiki.lazarus.freepascal.org/User:Rocarobin
 :D

motaz

  • Sr. Member
  • ****
  • Posts: 385
    • http://code.sd
Re: How to create FireBird database from Lazarus
« Reply #13 on: October 23, 2010, 01:53:25 pm »
I've asked this question when I start development of Turbo Bird project.  :)
Now it is there http://www.code.sd

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads