[Lazarus] [Long and partially OT] Database (OOP) programming: beginners manual?

Lukasz Sokol el.es.cr at gmail.com
Tue Sep 20 14:53:58 CEST 2011


Hi,
this may not be entirely on-topic to this list, apologies for that;
(But since I am (currently) using Lazarus 0.9.28.2 r22279 FPC 2.2.4,
(and planning to upgrade to latest stable 0.9.30/2.4.something /windows/ installer distribution),
the offtopic is somehow diminished)

I looked up http://wiki.lazarus.freepascal.org/ODBCConn, http://wiki.lazarus.freepascal.org/Databases, read http://wiki.lazarus.freepascal.org/Lazarus_DB_Faq so far,
I recreated and run successfully the example (the one with dbgrid) from 
http://www.lazarus.freepascal.org/index.php?topic=3329.0, on an
existing database; (yes the UsePrimaryKeyAsKey is unsupported in ODBC, 
TSQLQuery has to have that set as false otherwise ODBC driver throws errors)

As at some point I will have to use other (say Firebird) access 
without using visual components, I am trying to explore as much
as possible with RAD... 

I never used the OOP approach to database programming before, 
hence I feel like I am trying to do a second step before doing
the first... 

Where can I find some absolute beginners guide to 
OOP database (well maybe not /that/ absolute but answering questions
like - what's the idea behind the splitting the database access 
into Connection, Query, Transaction and DataSource? Or some actually /helpful/
examples of reading, writing, updating, deleting etc. data using this
paradigm)
I mean I can see what it does but I feel like I'm not entirely in
control of what happens at which stage... and that's disturbing :)
What I know so far is like showing a 'Hello World' program to a beginner, 
and expecting he'll be absolutely _stunned_ at the beauty and simplicity of it,
but the beginner goes "oh what the heck, this just spits 'Hello World' on your screen,
I don't get it what's the whole fuss about...? And what /exactly/ is this 
supposed to demonstrate to me?"

(I'm slightly more familiar with microcontroller programming, in case somebody thinks
I'm totally ignorant...)

(

Now for more on-topic:
I have a testing app using one of the examples as the base of it,
the one with dbgrid:

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Label1.Caption = 'ODBC Disconnected' then
    if OpenDialog1.Execute then
      begin

        ODBCConnection1.Params.Add('DBQ='+OpenDialog1.FileName);
       // ODBCConnection1.Open;
        SQLQuery1.SQL.Clear;
        SQLQuery1.SQL.Add('SELECT * FROM MyTable');
        SQLQuery1.Open;  // SIGSEGV when calling a second time
        exit;
      end;

  if Label1.Caption = 'ODBC Connected' then
    begin
      SQLQuery1.Close;
      ODBCConnection1.Close;
      exit;
    end;
end;  
 
So I can actually point to the MDB file I want to look into,
but then, when I close it (using the SQLQuery.Close part of the above), 
and then try to open it again (using the first part again) I get a 
'External: SIGSEGV' at the SQLQuery1.Open; call.
(This happens regardless of whether I have the SQLQuery.Close call for the
closing case or not)

?

)

(Hope I did not bore everybody yet...)
Thanks in advance,
Lukasz





More information about the Lazarus mailing list