Recent

Author Topic: [SOLVED] MySQL SELECT is NOT working right.  (Read 4337 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
[SOLVED] MySQL SELECT is NOT working right.
« on: December 15, 2017, 06:23:36 pm »
I am confused and  >:( frustrated to the max that I can't seem to figure out this simple BUG. I am running Lazarus 1.2.4 and fpc 2.6.4.

I successfully installed mysql server and apache. They work as they should. I can pull up default webpage and create MySQL database and tables. I even created a simple PHP webpage to access MySQL database and it works as it should. However, I wrote a simple program using Lazarus that suppose to be querying the MySQL database table. For the most part, it is working as it should, but for the life of me I can't seem to figure out why SELECT SQL statement won't execute. I get NO errors whatever. Every time I run the SELECT SQL statement, it returns with 0 or ZERO record count, when I obviously know that the table I am querying has about 10 different records. I verified the table using phpMysqladmin webpage. What is interesting to note here is that UPDATE and DELETE SQL statements work flawlessly with no problem at all. I also made sure to give the database user FULL PRIVILEGES. Here is the OFFENDING SELECT SQL statement.

Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Text := 'SELECT * FROM signals WHERE TagName = "'+f.TagName+'"';
  2. SQLQuery1.ExecSQL;

This SELECT SQL statement expected to return at least one record, because f.TagName should be in the table. But as I said, it is ALWAYS returning ZERO record. I don't understand it.

Any help will be GREATLY appreciate it.
« Last Edit: December 15, 2017, 08:06:39 pm by Awesome Programmer »

ASerge

  • Hero Member
  • *****
  • Posts: 2240
Re: MySQL SELECT is NOT working right.
« Reply #1 on: December 15, 2017, 06:55:31 pm »
Code: Pascal  [Select][+][-]
  1. SQLQuery1.Open;

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: MySQL SELECT is NOT working right.
« Reply #2 on: December 15, 2017, 08:05:46 pm »
 :-[ What Really!!!!!!!!!

OMG It works!!!!!!!!!!!!

But I read somewhere that when you call ExecSQL procedure, it will automatically open SQLQuery and then execute the SQL statement. I guess, it is not always true.

Thank you.  :D

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: MySQL SELECT is NOT working right.
« Reply #3 on: December 16, 2017, 06:24:57 am »
But I read somewhere that when you call ExecSQL procedure, it will automatically open SQLQuery and then execute the SQL statement. I guess, it is not always true.
Your description is not wrong, BUT ExecSQL is for queries that don't return result (INSERT, UPDATE, DELETE) while Open is for the ones that do (SELECT, SHOW). i.e. Open does additional work (parsing the returned rows) that ExecSQL doesn't.

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 451
  • Programming is FUN only when it works :)
    • Cool Technology
Re: [SOLVED] MySQL SELECT is NOT working right.
« Reply #4 on: December 20, 2017, 10:40:51 pm »
 :o
OMG!!!
I never knew that. You always learn something new everyday....

I would give you 10,000,000 points if there is such a thing on this Lazarus forum, Leledumbo...  :D

I am glad I logged back in to read my post.

Thank you.
« Last Edit: December 20, 2017, 10:48:29 pm by Awesome Programmer »

 

TinyPortal © 2005-2018