Recent

Author Topic: Problems in TSQLQuery  (Read 12893 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Problems in TSQLQuery
« Reply #15 on: March 27, 2012, 05:37:40 pm »
Are you sure your fpc and Lazarus versions match?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Problems in TSQLQuery
« Reply #16 on: March 27, 2012, 05:58:54 pm »
well, i've downloaded the latest file and installed it, but before i removed the old one first
then, when i tried running it, that happens

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Problems in TSQLQuery
« Reply #17 on: March 27, 2012, 06:01:05 pm »
actually this got me wondering, what does the error mean?

EDIT: it's finally getting to wor again
I reinstalled the whole program
« Last Edit: March 27, 2012, 06:10:37 pm by workinghard »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Problems in TSQLQuery
« Reply #18 on: March 27, 2012, 06:13:46 pm »
actually this got me wondering, what does the error mean?
It means your unit3.lfm and/or unit5.lfm has a LogEvents property for Mysql50Connection1 which is not recognised by the lazarus/fpc version you have now. Edit the lfm files and just delete the line containing LogEvents.

There are some other errors in you units:
- unit3:
Code: [Select]
Name: TLabeledEdit; 'Name' is already defined for a class and can't be re-used. Change to another identifier.

-unit5:
Code: [Select]
params.parambyname('Address').AsString := Address.text;There is no TEdit named 'Address' and it should be parambyname('Address').AsString, without the params.
And get rid of that awful SQL statement.  ;)

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Problems in TSQLQuery
« Reply #19 on: March 27, 2012, 06:26:53 pm »
ahh... i see

also, about my nasty SQL statement, I'll fix it, and maybe we can see the results  :P

EDIT:
After some tweaking, it still gave me the same error
the code:
Code: [Select]
unit Unit4;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, mysql50conn, sqldb, FileUtil, Forms, Controls, Graphics,
  Dialogs, StdCtrls;

type

  { TForm3 }

  TForm3 = class(TForm)
    Button1: TButton;
    edAddress: TEdit;
    Edwater: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    MySQLconnection: TMySQL50Connection;
    querycalc: TSQLQuery;
    transcalc: TSQLTransaction;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.lfm}

{ TForm3 }

procedure TForm3.Button1Click(Sender: TObject);
begin
    querycalc.Close;
    querycalc.sql.Clear;
    querycalc.sql.add('
INSERT INTO trmt(Address,date,pay)
VALUES((
SELECT M.Address
FROM master AS M WHERE M.Address = edAddress),CURRENT_TIMESTAMP,(
SELECT((M.Land*RM.RLandRate)+(M.House*RM.BuildingRate))
FROM Master AS M,rmnt AS RM
WHERE M.Cluster = RM.Cluster AND M.Alamat=edAddress)');
    querycalc.params.parambyname('Address').AsString := edAddress.Text;
    querycalc.execSQL;
  end;



end.
« Last Edit: March 28, 2012, 01:13:42 am by workinghard »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Problems in TSQLQuery
« Reply #20 on: March 28, 2012, 09:10:33 am »
Quote
After some tweaking, it still gave me the same error
You're still make the same error. Replace
Code: [Select]
querycalc.params.parambyname('Address').AsString := edAddress.Text; with
Code: [Select]
querycalc.parambyname('Address').AsString := edAddress.Text;
I note that you got rid of the 'with SQLQuery1 do' which is the right thing to do. Makes it much easier to detect errors and the code completion works much better without 'with'.

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Problems in TSQLQuery
« Reply #21 on: March 28, 2012, 11:54:04 am »
Ok, i've changed the code
But it gave me another error saying
"error: identifier idents no member "parambyname""
That's why in the other units, i've stayed away from removing the params before parambyname

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Problems in TSQLQuery
« Reply #22 on: March 28, 2012, 12:03:01 pm »
The "params" is needed.  It is a pointer to a TParams object.  Only with TParams is there a "parambyname".

In your last code fragment I don't see you using :Address as parameter in the SQL statement.  It says "edAddress".
« Last Edit: March 28, 2012, 12:05:33 pm by Arbee »
1.0/2.6.0  XP SP3 & OS X 10.6.8

workinghard

  • Jr. Member
  • **
  • Posts: 74
Re: Problems in TSQLQuery
« Reply #23 on: March 28, 2012, 12:40:59 pm »

In your last code fragment I don't see you using :Address as parameter in the SQL statement.  It says "edAddress".

I don't really get the meaning of this
So i should change the editbox (edAddress) to address as well?

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Problems in TSQLQuery
« Reply #24 on: March 28, 2012, 12:58:09 pm »
No,  I mean that in your last code fragment the SQL code looks like this:
Code: [Select]
querycalc.sql.add('
INSERT INTO trmt(Address,date,pay)
VALUES((
SELECT M.Address
FROM master AS M WHERE M.Address = edAddress),CURRENT_TIMESTAMP,(
SELECT((M.Land*RM.RLandRate)+(M.House*RM.BuildingRate))
FROM Master AS M,rmnt AS RM
WHERE M.Cluster = RM.Cluster AND M.Alamat=edAddress)');

whereas its last line should read:
Code: [Select]
WHERE M.Cluster = RM.Cluster AND M.Alamat= :Address)');

1.0/2.6.0  XP SP3 & OS X 10.6.8

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Problems in TSQLQuery
« Reply #25 on: March 28, 2012, 01:05:11 pm »
I also have the feeling your SQL statement is missing a closing bracket.
1.0/2.6.0  XP SP3 & OS X 10.6.8

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: Problems in TSQLQuery
« Reply #26 on: March 28, 2012, 01:18:37 pm »
And one more ..... looking at your SQL query, I think you could do it with one SELECT in the INSERT:
Code: [Select]
INSERT INTO trmt(Address,date,pay)
VALUES(
(
SELECT M.Address, CURRENT_TIMESTAMP,  ((M.Land*RM.RLandRate)+(M.House*RM.BuildingRate))
FROM Master AS M,rmnt AS RM
WHERE RM.Cluster = M.Cluster AND M.Address = :Address
)
)
Not sure if that occasionally will give null results if the linke between MASTER and rmnt is not correct, but you could give it a try.
1.0/2.6.0  XP SP3 & OS X 10.6.8

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Problems in TSQLQuery
« Reply #27 on: March 28, 2012, 04:04:12 pm »
The "params" is needed.  It is a pointer to a TParams object.  Only with TParams is there a "parambyname".
In fpc 2.4.4 TCustomSQLQuery had already a public function ParamByName(Const AParamName : String) : TParam;

That means that the OP is still using his old compiler. Aren't we all just running in circles here? The same problems always coming back. OP is not listening or doesn't understand what we are saying.

 

TinyPortal © 2005-2018