Hi,
I'm sure some of you have been following my learning curve with Lazarus and
using SQLdb. At last I think I have the issue.
I think I have now discovered the error in updating the data on the postgres
database. The sqlquery is passing a bad string to the postgres database
engine. In my case the the following is passed:
Update arcust set custno = 'BRS', company = 'Blue Ribbon Stairs' where
(custno=BRS)
Notice that the BRS lacks single quotes. It should be (custno='BRS').
The append works - the insert statement was perfect.
Now how do I fix it?
John
below is the simple code to show the error:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
pqconnection, sqldb, StdCtrls, Buttons;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
PQConnection1: TPQConnection;
SQLQuery1: TSQLQuery;
SQLTransaction1: TSQLTransaction;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
self.PQConnection1.DatabaseName :='Real-Accounting';
self.PQConnection1.UserName:='johnf';
self.PQConnection1.HostName:='192.168.1.200';
self.PQConnection1.Password:='jfabiani';
self.PQConnection1.Transaction:=self.SQLTransaction1;
self.SQLQuery1.DataBase:=self.PQConnection1;
self.SQLQuery1.sql.clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
var mystring:string;
VAR mysqlstr:string;
begin
mysqlstr:= 'Select custno,company from arcust where custno =
'+''''+edit1.Text+'''';
self.SQLQuery1.SQL.Add(mysqlstr);
//self.SQLQuery1.SQL.Add(self.edit1.Text);
//mystring:={'}
// self.SQLQuery1.sql.Add('''');
mystring:=self.SQLQuery1.SQL.Text;
self.SQLQuery1.open;
self.edit2.Text:=sqlquery1.FieldByName('company').AsString;
self.edit2.Refresh;
self.SQLQuery1.Edit;
end;
procedure TForm1.Button2Click(Sender: TObject);
Var updtestr:string;
begin
//self.sqlquery1.Clear;
//self.SQLQuery1.Edit;
SQLQuery1.FieldByName('company').AsString:= self.edit2.Text;
//updtestr:='update set company = '+''''+edit2.text+''''+' where custno = '+
'+''''+edit1.Text+'''';
//self.SQLQuery1.SQL.Text:=;
//self.SQLQuery1.Append;
//self.SQLQuery1.FieldByName('custno').AsString:='BRS';
//self.SQLQuery1.FieldByName('company').AsString:='JFCS';
self.SQLQuery1.Post;
self.SQLQuery1.ApplyUpdates;
self.SQLTransaction1.Commit;
self.SQLQuery1.Close;
end;
initialization
{$I unit1.lrs}
end.
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives