On Tue, 2006-09-19 at 11:03 +0200, A.J. Venter wrote:
> On Tuesday 19 September 2006 10:47, Joost van der Sluis wrote:
> > Run it in a debugger and tell us on which line it crashes?
> The backtrace says it crashes on line 96 - the mysql_query call, I ran it 
> through gdb and got the following output:
> 
> (gdb) run
> Starting program: /tmp/project1
> [Thread debugging using libthread_db enabled]
> [New Thread 16384 (LWP 10618)]
> 
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 16384 (LWP 10618)]
> 0x40321a08 in mysql_slave_send_query () from /usr/lib/libmysqlclient.so.14

Probably a mysql-version-problem, or you confused pointers and variables
a bit.

> > And you're using the mysql4 unit. You know what the consequences are?
> > What's the version of you're mysql-client?
> Consequences ? I understood that you needed mysql4 for versions after 
> mysql-version 3.
> I have mysql version 4.1.13.
> Should I be using a different unit name ?

mysql41

mysql4 is for mysql 4.0 only, and only exist for backwards-
compatibility. Please use mysql40, mysql41 or mysql50

> > (And ask yourself: do I really want to use mysql?)
> This one I haven't got much choice over. It has to be a network transparent 
> SQL server, and it has to be something just about every distro comes with, 
> and which people know how to use - and some of the component parts will quite 
> possible be written in other languages like PHP (this isn't fixed but quite 
> likely).

Every self-respecting distribution has postgres for real users, and
mysql for the weenies.

And your customers, do you think they like it that if they upgrade their
workstations, they have to ask you for a newer version of your program?

You'll have to distribute executables for every mysql-version there is
and will be....

For start I would use the dynamically loaded units. (mysqlxx_dyn)

And for more info about why you shoudn't use mysql, or a more detailed
explanation about the problem above, search for mails from me on this
maillinglist.


> > On Tue, 2006-09-19 at 10:13 +0200, A.J. Venter wrote:
> > > Mmm,
> > > So does nobody know what I'm doing wrong ? Or is it not a problem in my
> > > code ? Any idea what I should check ?
> > >
> > > A.J.
> > >
> > > On Monday 18 September 2006 15:17, A.J. Venter wrote:
> > > > I have just started on a new project, which is mysql backed - beginning
> > > > with a fairly abstract unit which a large number of different lazarus
> > > > programs will use to communicate with the DB.
> > > >
> > > > But I ran into a very strange problem quite early on, I can connect to
> > > > the DB without hassles, but as soon as I try to do a query - I get a
> > > > crash, and I have no idea why... :S
> > > >
> > > > My current test calls look like this:
> > > >
> > > > ZC_DBConnect;
> > > > ZC_Settings : TZC_Settings.Create;
> > > >         Writeln(ZC_Settings.GetPricePerUnit);
> > > >
> > > > TraceBack says it's crashing on line 96:
> > > >   if (mysql_query(socket,pchar(Query)) < 0) then
> > > >
> > > >
> > > > The unit in full goes:
> > > > unit libzybacafe;
> > > >
> > > > {$mode objfpc}{$H+}
> > > >
> > > > interface
> > > >
> > > > uses
> > > >   Classes, SysUtils,dialogs,mysql4;
> > > >
> > > > procedure ZC_DBConnect;
> > > > Function ZC_DBQuery(Query:String):PMYSQL_RES;
> > > >
> > > > type
> > > >   TZC_Settings = class
> > > >   private
> > > >    {Private Declarations}
> > > >          FCurrencySymbol : String;
> > > >          FUnitLength : Integer;
> > > >          FPricePerUnit : Real;
> > > >          FResult : PMySQL_RES;
> > > >          FRow: MYSQL_ROW;
> > > >          Procedure LoadFromDB;
> > > >          Procedure SaveToDB;
> > > >     public
> > > >     { public declarations }
> > > >          Function GetCurrencySymbol : String;
> > > >          Function GetUnitLength : Integer;
> > > >          Function GetPricePerUnit: Real;
> > > >          Procedure SetCurrencySymbol(NewSymbol:String);
> > > >          Procedure SetUnitLength(NewLength:Integer);
> > > >          Procedure SetPricePerUnit(NewPrice : Real);
> > > >   end;
> > > >
> > > > Var
> > > >  Socket : PMysQL;
> > > >
> > > > implementation
> > > >
> > > > procedure ZC_DBConnect;
> > > > Var
> > > >     DBCFG : TSTringList;
> > > >     I : Integer;
> > > >     H,U,P,D : String;
> > > >   qmysql : TMYSQL;
> > > >   alloc : PMYSQL;
> > > >
> > > > Begin
> > > > DBCFG := TSTringList.Create;
> > > > Try
> > > > {$IFDEF Unix}
> > > >    DBCFG.LoadFromFile('/etc/zybacafe.cfg');
> > > > {$ENDIF}
> > > > {$IFDEF Win32}
> > > >    DBCFG.LoadFromFile('C:\Program Files\ZybaCafe\zybacafe.cfg');
> > > > {$ENDIF}
> > > > except
> > > >       ShowMessage ('Error Loading database configuration !');
> > > >       Halt;
> > > > end;
> > > > For I := 0 to DBCFG.Count -1 do
> > > > begin
> > > >      If pos('HOST=',uppercase(DBCFG[I])) <> 0 then
> > > >         begin
> > > >              H := DBCFG[I];
> > > >              Delete(H,1,pos('=',H));
> > > >         end;
> > > >      If pos('USERNAME=',uppercase(DBCFG[I])) <> 0 then
> > > >         begin
> > > >              U := DBCFG[I];
> > > >              Delete(U,1,pos('=',U));
> > > >         end;
> > > >      If pos('PASSWORD=',uppercase(DBCFG[I])) <> 0 then
> > > >         begin
> > > >              P := DBCFG[I];
> > > >              Delete(P,1,pos('=',P));
> > > >         end;
> > > >      If pos('DATABASE=',uppercase(DBCFG[I])) <> 0 then
> > > >         begin
> > > >              D := DBCFG[I];
> > > >              Delete(D,1,pos('=',D));
> > > >         end;
> > > >
> > > > end;
> > > >  alloc := mysql_init(PMYSQL(@qmysql));
> > > >   socket :=  mysql_real_connect(alloc, pchar(h), pchar(u),
> > > > pchar(p),pchar(d), 0, nil, 0);
> > > >   if socket=Nil then
> > > >     begin
> > > >          ShowMessage('Error connecting to
> > > > database:'+LineEnding+StrPas(mysql_error(@qmysql)));
> > > >          halt;
> > > >     end;
> > > > end;
> > > >
> > > > Function ZC_DBQuery(Query:String):PMYSQL_RES;
> > > > Var RecBuf : PMYSQL_RES;
> > > > Begin
> > > >   if (mysql_query(socket,pchar(Query)) < 0) then
> > > >      begin
> > > >        ShowMessage('Query failed '+ StrPas(mysql_error(socket)));
> > > >      end
> > > > else
> > > >      begin
> > > >        recbuf := mysql_store_result(socket);
> > > >        if RecBuf=Nil then
> > > >        begin
> > > >          ShowMessage('Query returned nil result.');
> > > >        end else
> > > >         ZC_DBQuery := RecBuf;
> > > >      end;
> > > > end;
> > > >
> > > > Procedure TZC_Settings.LoadFromDB;
> > > > Var Result : PMYSQL_RES;
> > > >     Q : String;
> > > > Begin
> > > >     FResult := ZC_DBQuery('SELECT * FROM settings;');
> > > >     FRow := Mysql_Fetch_Row(FResult);
> > > >      If FRow = Nil then
> > > >      begin
> > > >         showMessage('You have no stored
> > > > site-settings.'+LineEnding+'Setting all to defaults');
> > > >         FCurrencySymbol := '$';
> > > >         FUnitLength := 1;
> > > >         FPricePerUnit := 1.0;
> > > >          Q := 'INSERT INTO settings VALUES("","'+FCurrencySymbol;
> > > >          Q :=
> > > > Q+'","'+IntToStr(FUnitLength)+'","'+FloatToStr(FPricePerUnit)+'");';
> > > >          Result := ZC_DBQuery(Q);
> > > >      end else
> > > >      begin
> > > >        FCurrencySymbol := FRow[1];
> > > >        FUnitLength := StrToInt(FRow[2]);
> > > >        FPricePerUnit := StrToFloat(FRow[3]);
> > > >      end;
> > > >
> > > > end;
> > > >
> > > > Procedure TZC_Settings.SaveToDB;
> > > > Var
> > > > Query : String;
> > > > Begin
> > > >    Query := 'UPDATE TABLE settings SET
> > > > currencysymbol="'+FCurrencySymbol; Query :=
> > > > Query+'",unitlength="'+IntToStr(FUnitLength);
> > > >    Query := Query+'",priceperunit="'+FloatToStr(FPricePerUnit)+';';
> > > >    FResult := ZC_DBQuery(Query);
> > > > end;
> > > >
> > > > Function TZC_Settings.GetCurrencySymbol : String;
> > > > Begin
> > > >      LoadFromDB;
> > > >      GetCurrencySymbol := FCurrencySymbol;
> > > > end;
> > > >
> > > > Function TZC_Settings.GetUnitLength : Integer;
> > > > Begin
> > > >      LoadFromDB;
> > > >      GetUnitLength := FUnitLength;
> > > > end;
> > > >
> > > > Function TZC_Settings.GetPricePerUnit: Real;
> > > > Begin
> > > >      LoadFromDB;
> > > >      GetPricePerUnit := FPricePerUnit;
> > > > end;
> > > >
> > > > Procedure TZC_Settings.SetCurrencySymbol(NewSymbol:String);
> > > > Begin
> > > >      FCurrencySymbol := NewSymbol;
> > > >      SaveToDB;
> > > > end;
> > > >
> > > > Procedure TZC_Settings.SetUnitLength(NewLength:Integer);
> > > > Begin
> > > >      FUnitLength := NewLength;
> > > >      SaveToDB;
> > > > end;
> > > >
> > > > Procedure TZC_Settings.SetPricePerUnit(NewPrice : Real);
> > > > Begin
> > > >     FPricePerUnit := NewPrice;
> > > >     SaveToDB;
> > > > end;
> > > >
> > > > initialization
> > > >
> > > >
> > > > end.
> 
-- 
Met vriendelijke groeten,

  Joost van der Sluis
  CNOC Informatiesystemen en Netwerken
  http://www.cnoc.nl

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to