Recent

Author Topic: Brook 1.0 - SQLdb Driver [RE-OPENED]  (Read 11565 times)

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Brook 1.0 - SQLdb Driver [RE-OPENED]
« on: January 30, 2013, 07:51:28 pm »
Team,

I have been playing around with Brook Framework and I must say I am thoroughly impressed so far!! 8-)

I have a question: Most (all?) of the demos have a SqlLite3 schema and implementation; a number may have PostgreSQL schemas but no implementation; nothing at all for the other DBMS... but of course the whole point of a demo is to pick up from there and figure it out. However, I cannot figure out how to use SqlDB to connect to any other database but SQLLite:

Code: [Select]
BrookSettings.Configuration := 'library=sqldb;driver=pqconnection;host=127.0.0.1;user=USERNAME;password=PASSWORD;database=TESTDB';
I have tried replacing the driver with PQ, Postgres, PostgreSQL, MySQL55, MySQL51.. (of course each to its respective server) nothing works. However dropping a TPQConnection or a TMysql5*conn on a form and setting the proper parameters works fine.

What am I missing?

Thanks.

Kind regars
JamHitz
« Last Edit: January 31, 2013, 05:26:55 pm by jamhitz »

Silvio Clécio

  • Guest
Re: Brook 1.0 - SQLdb Driver
« Reply #1 on: January 30, 2013, 07:56:08 pm »
Hello friend,

In brokers unit, just declare your connection unit, eg:

https://github.com/silvioprog/brook-site/blob/master/src/release/brokers.pas

Good luck! :)

Silvio Clécio

  • Guest
Re: Brook 1.0 - SQLdb Driver
« Reply #2 on: January 30, 2013, 07:57:17 pm »
... and change your configuration to:

Code: [Select]
BrookSettings.Configuration := 'library=sqldb;driver=postgresql;host=127.0.0.1;user=USERNAME;password=PASSWORD;database=TESTDB';

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: Brook 1.0 - SQLdb Driver
« Reply #3 on: January 30, 2013, 08:09:18 pm »
@SilvioProg

Eureka!!!! Can you see the smile?   :)  I am intent on writing a small (VEEEEERY basic) 101 tutorial on using  Brook for web programming using FPC/Laz. I hope in this way I will play my little part in making Brook what I  believe it has the potential to become - the number one Web Programming Framework for FPC/Laz. In the meantime I stumbling, falling and finding my way around using the demos and the documentation.

Thank you.

Kind regards
JamHitz
« Last Edit: January 30, 2013, 08:12:37 pm by jamhitz »

Silvio Clécio

  • Guest
Re: [SOLVED] Brook 1.0 - SQLdb Driver
« Reply #4 on: January 30, 2013, 08:29:19 pm »
Very nice friend! I saw the smile. :)

What the link to the site where you will post? We may publish it in the official community of Lazarus on Facebook, GooglePlus etc.

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: [SOLVED] Brook 1.0 - SQLdb Driver
« Reply #5 on: January 30, 2013, 08:37:46 pm »
I will most probably post it to the Lazarus wiki and/or on the BrookFramework website.

Silvio Clécio

  • Guest
Re: [SOLVED] Brook 1.0 - SQLdb Driver
« Reply #6 on: January 30, 2013, 08:39:51 pm »
Great!  ;)

It will be posted in future blog of Brook too! :-X

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #7 on: January 31, 2013, 05:35:05 pm »
I can now be able to connect to a DB. However, attempting to use TBrookTable or TBrookQuery (by alternating the commented lines):

Code: [Select]
procedure TMyAction.Get;
var db: TBrookDatabase;
    q: TBrookQuery;
    t: TBrookTable;
begin
    BrookSettings.Configuration := 'library=sqldb;driver=postgresql;host=SERVER;user=USER;password=PASS;database=db';
    try
        db := TBrookDatabase.Create;
        //q := TBrookQuery.Create(db);
        t := TBrookTable.Create(db, 'gateway');
        try
            WriteLn(t.AsJSON);

            //q.SQL.Text := 'SELECT id,name,description from gateway';
            //q.Open;
            //WriteLn(q.AsJSON);
        except
            on E:Exception do
                Write('ERROR:' + E.Message);
        end;
    finally
        FreeAndNil(db);
        FreeAndnil(q);
        FreeAndNil(t);
    end;

...brings up an error Premature end of script headers: cgi3 .

Ideas?

Thank you.

Silvio Clécio

  • Guest
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #8 on: February 02, 2013, 04:38:50 am »
Don't use BrookSettings.Configuration in actions, use it on the brokers unit.

You can facilitate decreasing the coding:

...
TMyAction = class(TBrookDBAction)
...

procedure TMyAction.Get;
begin
  Write(Table.Open.AsJSON); // or Table.AsJSON directly
end;
...
initialization
  TMyAction.Register('gateway', '*');

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #9 on: February 02, 2013, 11:55:05 am »
@Silvio

I've created a brand new project that uses TBrookDBAction instead of TBrookAction, but I still get the same error. Here is the broker:

Code: [Select]
unit brokers007;

{$mode objfpc}{$H+}

interface

uses
  BrookFCLCGIBroker, BrookUtils, BrookSQLdbBroker, PQConnection;

implementation

initialization
BrookSettings.Charset := 'library=sqldb;driver=postgresql;host=127.0.0.1;user=USERNAME;password=PASSWORD;database=TESTDB';
BrookSettings.Page404 := '404.html';
BrookSettings.Page500 := '500.html';
end.

..and here is the action:

Code: [Select]
unit umain007;

{$mode objfpc}{$H+}

interface

uses
  BrookDBAction, fpJSON;

type
  TMyAction = class(TBrookDBAction)
  public
      procedure Get; override;
  end;

implementation

{ TMyAction }

procedure TMyAction.Get;
begin
    Write(Table.Open.AsJSON);
end;

initialization
  TMyAction.Register('gateway','*');

end.

See the attachment for the response.

JamHitz
« Last Edit: February 02, 2013, 11:56:38 am by jamhitz »

Silvio Clécio

  • Guest
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #10 on: February 05, 2013, 07:02:38 pm »
Hello, sorry for my delay.

So, try to run the demo "\repository\git\brookframework\demos\simple\helloworld\cgi\cgi1.lpi". I need to find out if the error is in your DB or in your HTTP server.

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #11 on: February 06, 2013, 10:54:24 pm »
Hi

I have tested MOST of the demos in the /simple, /http and /others sub-directories.  They all work as expected. It is those in the /db sub-directory that are a problem.

OpenSuse 12/Lazarus 1.1/fpc 2.7/PostgreSQL 9.1/MySQL 5.5

JamHitz

Silvio Clécio

  • Guest
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #12 on: February 07, 2013, 12:16:19 am »
You can connect using pure SQLdb? Take a test, add a SQLConnector1 in a form and try to connect.

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #13 on: February 07, 2013, 05:27:05 am »
Yes, a regular SQLdb-based desktop application works just fine accessing the very same database with the very same credentials.

In fact CGI applications based of fpWeb and FreeSpider are accessing the database ok.

Silvio Clécio

  • Guest
Re: Brook 1.0 - SQLdb Driver [RE-OPENED]
« Reply #14 on: February 07, 2013, 11:40:56 am »
I don't know what can be, because I could not reproduce the error.

Download this demo:

http://www.sendspace.com/file/wkajve

And follow the steps below:

1. # zypper install sqlite3-devel ;
2. Open and run the project "project1.lpi";
3. Call http://localhost in your browser;

This allow you to set a break point and debug your application, running the it step by step with F8.

 

TinyPortal © 2005-2018