Recent

Author Topic: Why SQLquery make some changes and don't run as is typing  (Read 2408 times)

eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Why SQLquery make some changes and don't run as is typing
« on: September 14, 2023, 08:16:12 pm »
Look i have a sql witch is i wanna to run mysql, the question is my instruction going in one direcction and when I show the sql command to run show me different for example

SELECT *
    FROM departament As A
where A.HEAD_DEPT is null AND
     A.DEPT_NO is not null
    ORDER BY A.Department     

and send me error when i showmessage() show me this

SELECT *
    FROM departament As A
where A."HEAD_DEPT" is null AND
     A.DEPT_NO is not null
    ORDER BY A.Department

why change A."HEAD_DEPT"

that create a error message to run query
idea why going like that.....

thanks...

zeljko

  • Hero Member
  • *****
  • Posts: 1921
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Why SQLquery make some changes and don't run as is typing
« Reply #1 on: September 14, 2023, 08:29:21 pm »
And what is the error ?

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Why SQLquery make some changes and don't run as is typing
« Reply #2 on: September 14, 2023, 08:36:35 pm »
why change A."HEAD_DEPT"
Understandable that that throws an error. The quotes shouldn't be there.

But I can't understand anything of the rest of your post/text. What is changing this SQL?
You don't mention what you do exactly, what components, where you enter the SQL.
So we don't know what changes that SQL until you explain exactly what you do.

Maybe use your own language and put the Google Translator text below that.

eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #3 on: September 14, 2023, 08:39:41 pm »
The error show up...
Syntax error near to  A."HEAD_DEPT" is null AND

eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #4 on: September 14, 2023, 08:45:18 pm »
Ok  understand  also i don't know where was error as i going more deep checking what is the problem is when i can find more clear why that error.... thanks for your help and time...

i know when use sql with parameters change the sql for value get from parameters but on this particular not use any parameter... is directly.

   

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Why SQLquery make some changes and don't run as is typing
« Reply #5 on: September 14, 2023, 08:57:02 pm »
There is no component in Lazarus/FPC that I know of which would change this.

Which component are you using?

Only component I can think of is TDBTable where you don't fill the complete SQL but only the fields (and the component creates the SQL).

So give us more information on what components you are using and how you are filling in the SQL (via code or 'editor').


eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #6 on: September 14, 2023, 10:04:14 pm »
Just TSQLQuery with datasource

eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #7 on: September 14, 2023, 10:08:38 pm »
This the code
Code: Pascal  [Select][+][-]
  1. procedure TfTreeViewVes.FormShow(Sender: TObject);
  2. begin
  3.  SQLLLib.LibraryName:= WideString(ExtractFilePath(ParamStr(0)) + 'libmysql.dll');
  4.  SQLLLib.LoadLibrary;
  5.  memo1.Lines.Clear;
  6.  
  7.  if(SQLLLib.Enabled = True) then begin
  8.    if mysql57c.Connected = true then begin ;
  9.      SQLQuery3.Open;
  10.    end else begin
  11.      mysql57c.Connected:=true;
  12.      SQLQuery3.Open;
  13.      showmessage(SQLQuery3.sql.text);
  14.  
  15.    end;
  16.  end;
  17.  
  18.  
  19. end;
  20.  

and this what contain on sqlquerey...

SELECT  A.*
    FROM departament As A
where A.HEAD_DEPT is null AND
     A.DEPT_NO is not null
    ORDER BY A.Department

eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #8 on: September 14, 2023, 10:13:24 pm »
This is tables I using....

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: Why SQLquery make some changes and don't run as is typing
« Reply #9 on: September 15, 2023, 12:56:30 am »
And if you put the showmessage(SQLQuery3.sql.text); at the top of the TfTreeViewVes.FormShow procedure?

That does it say then?

Try to put that line in several places and find out when it is changing.

TSQLQuery shouldn't change your SQL on it's own like that.

eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #10 on: September 15, 2023, 01:43:54 am »
Well I made some changes first i change the sql script

like that

SELECT  A.*
    FROM departament As A
where A.HEAD_DEPT is null
     A.DEPT_NO is not null
    ORDER BY A.Department

you can see and on this line was removed
A.HEAD_DEPT is null

showmessage() is before to open sqlquery.
and showm this..

SELECT  A.*
    FROM departament As A
where A."HEAD_DEPT" is null AND
     A.DEPT_NO is not null
    ORDER BY A.Department

where was added    AND
and who change to A."HEAD_DEPT"

really i very surprise



eldonfsr

  • Hero Member
  • *****
  • Posts: 582
Re: Why SQLquery make some changes and don't run as is typing
« Reply #11 on: September 15, 2023, 03:05:23 am »
I fund the problem DBTREEView change the sql sentence

at this process

Code: Pascal  [Select][+][-]
  1. procedure TDBTreeView.UpdateSQL;
  2. begin
  3.   if DataSet is TSQLQuery then begin
  4.     if fSQLWherePosition = -1 then
  5.       Raise Exception.Create('No where clause detected.');
  6.  
  7.     if not assigned(FExpandNode) and assigned(FUpdateNode)  then begin {Scrolling dataset}
  8.       TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+'"' + FKeyField + '" = :KEY_VALUE AND ';
  9.       //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_KEY_VALUE')
  10.       end
  11.     else
  12.     if (Items.Count = 0) then begin
  13.       {Need to Load Root Nodes}
  14.       TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where '+GetRelationNameQualifier+'"' + FParentField + '" is null AND ';
  15.       //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null')
  16.       end
  17.     else
  18.     if assigned(FExpandNode) then
  19.     begin
  20.       TSQLQuery( DataSet ).SQL[ fSQLWherePosition ] := 'where ( '+GetRelationNameQualifier+'"' + FParentField + '" = :PARENT_VALUE OR '+GetRelationNameQualifier+'"' + FKeyField + '" = :PARENT_VALUE ) AND '
  21.       //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE');
  22.       //Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true);
  23.     end;
  24.   end;
  25. end;
  26.  
  27.  

let me work on this and see how to change...
Thanks for our your help i Appreciate that to much....
 

 

TinyPortal © 2005-2018