* * *

Author Topic: Connecting to mariadb  (Read 1897 times)

jshand2010

  • Full Member
  • ***
  • Posts: 217
Connecting to mariadb
« on: February 24, 2017, 02:39:43 am »
I am having trouble trying to get this code to work...  can someone let me know where i'm going wrong?  i get the error about a transaction not being set.
Manjaro Linux 15.12 Rolling Release, fpc 3.0.1 fixes, lazarus trunk

mangakissa

  • Hero Member
  • *****
  • Posts: 684
Re: Connecting to mariadb
« Reply #1 on: February 24, 2017, 08:41:23 am »
What error?
Piece of code instead of whole project?
Lazarus 1.6 (32b) / FPC 3.0
Windows Vista /  10

jshand2010

  • Full Member
  • ***
  • Posts: 217
Re: Connecting to mariadb
« Reply #2 on: February 24, 2017, 11:21:10 am »
just look into the provars.pas file.  this is where the error is.  it happens as i load loadlogintb procedure.  i presume the loaddb; code is correct to get things started
Manjaro Linux 15.12 Rolling Release, fpc 3.0.1 fixes, lazarus trunk

Thaddy

  • Hero Member
  • *****
  • Posts: 3697
Re: Connecting to mariadb
« Reply #3 on: February 24, 2017, 12:30:46 pm »
Try mysql57conn -->> mysql56conn
That one is still MariaDb compatible.

Note we would probably need to start a new component for MariaDb. It is diverging.
I did not test this yet, but just try first.
« Last Edit: February 24, 2017, 12:36:46 pm by Thaddy »
Why do the Danish always try to fuck up any programming language?

jshand2010

  • Full Member
  • ***
  • Posts: 217
Re: Connecting to mariadb
« Reply #4 on: February 24, 2017, 10:49:23 pm »
thanks thaddy, i forgot about that technicality.  i will test it and let you know
Manjaro Linux 15.12 Rolling Release, fpc 3.0.1 fixes, lazarus trunk

jshand2010

  • Full Member
  • ***
  • Posts: 217
Re: Connecting to mariadb
« Reply #5 on: February 24, 2017, 11:43:11 pm »
here is the code snippet:  it still doesn't work with mysql56conn:

a:=0;
  clearul(a);
  cleartl;

  loaddb;

  try
    if (conn.Connected=true) then begin
      query.Close;
      query.SQL.Clear;
      query.SQL.Add('select uname, pword from userlogintb;');
      query.ExecSQL;
      query.Last;
    end;
  except
    on err: ESQLDatabaseError do begin
      ShowMessage(err.Message);
      ShowMessage(err.UnitName);
    end;
  end;   
Manjaro Linux 15.12 Rolling Release, fpc 3.0.1 fixes, lazarus trunk

rvk

  • Hero Member
  • *****
  • Posts: 2494
Re: Connecting to mariadb
« Reply #6 on: February 25, 2017, 12:31:48 am »
You set the database in the transaction.

But you should also set the transaction in the connection and the sqlquery. You forgot to do that.

mangakissa

  • Hero Member
  • *****
  • Posts: 684
Re: Connecting to mariadb
« Reply #7 on: February 27, 2017, 09:43:46 am »
Query.ExecSQL doesn't get a dataset for you. So there are no records to check.
Lazarus 1.6 (32b) / FPC 3.0
Windows Vista /  10

Thaddy

  • Hero Member
  • *****
  • Posts: 3697
Re: Connecting to mariadb
« Reply #8 on: February 27, 2017, 11:45:49 am »
Query.ExecSQL doesn't get a dataset for you. So there are no records to check.
Why does it is name says QueryXXX then? A query is supposed to return a dataset.... Is this true? Then it's a bug. If only poor language choice.

Query means: I am asking and would like to have (an) answer(s). Usually you get one at least....
« Last Edit: February 27, 2017, 11:51:45 am by Thaddy »
Why do the Danish always try to fuck up any programming language?

rvk

  • Hero Member
  • *****
  • Posts: 2494
Re: Connecting to mariadb
« Reply #9 on: February 27, 2017, 12:02:31 pm »
Query.ExecSQL doesn't get a dataset for you. So there are no records to check.
Why does it is name says QueryXXX then? A query is supposed to return a dataset.... Is this true? Then it's a bug. If only poor language choice.
 I am asking and would like to have (an) answer(s). Usually you get one at least....
Although this is a TSQLQuery component, the ExecSQL does NOT return a dataset. It just executes a statement. So consider the ExecSQL a "helper" function which you use to execute a statement when you don't need to have a result-set. You could also use a separate TSQLScript or even use the .ExecuteDirect() from the connection-component instead.

From the manual:
http://www.freepascal.org/docs-html/fcl/sqldb/tcustomsqlquery.execsql.html

Quote
ExecSQL will execute the statement in TSQLQuery.SQL, preparing the statement if necessary. It cannot be used to get results from the database (such as returned by a SELECT statement): for this, the Open method must be used.

This is a well known fact of the .ExecSQL() function.

mangakissa

  • Hero Member
  • *****
  • Posts: 684
Re: Connecting to mariadb
« Reply #10 on: February 27, 2017, 12:18:53 pm »
Create an example for check login. It's not the best solution, but it works.
Lazarus 1.6 (32b) / FPC 3.0
Windows Vista /  10

Thaddy

  • Hero Member
  • *****
  • Posts: 3697
Re: Connecting to mariadb
« Reply #11 on: February 27, 2017, 12:30:30 pm »
[Although this is a TSQLQuery component, the ExecSQL does NOT return a dataset. It just executes a statement. So consider the ExecSQL a "helper" function which you use to execute a statement when you don't need to have a result-set. You could also use a separate TSQLScript or even use the .ExecuteDirect() from the connection-component instead.

From the manual:
http://www.freepascal.org/docs-html/fcl/sqldb/tcustomsqlquery.execsql.html

Quote
ExecSQL will execute the statement in TSQLQuery.SQL, preparing the statement if necessary. It cannot be used to get results from the database (such as returned by a SELECT statement): for this, the Open method must be used.

This is a well known fact of the .ExecSQL() function.
So I was right (again). Semantics. Design error. Problem is that most people have no clue about software design.Introducing this functionality in the wrong place is moronic. It is wrong.  Go shopping for apples and bring back pears.
« Last Edit: February 27, 2017, 12:33:00 pm by Thaddy »
Why do the Danish always try to fuck up any programming language?

mangakissa

  • Hero Member
  • *****
  • Posts: 684
Re: Connecting to mariadb
« Reply #12 on: February 27, 2017, 12:39:02 pm »
If this is a design error, all database frameworks are wrong designed. I can not tell you which framework gives a dataset back when using execSQL.
Lazarus 1.6 (32b) / FPC 3.0
Windows Vista /  10

mangakissa

  • Hero Member
  • *****
  • Posts: 684
Re: Connecting to mariadb
« Reply #13 on: March 01, 2017, 07:41:56 am »
Create an example for check login. It's not the best solution, but it works.
Does it work?
Lazarus 1.6 (32b) / FPC 3.0
Windows Vista /  10

GetMem

  • Hero Member
  • *****
  • Posts: 2074
Re: Connecting to mariadb
« Reply #14 on: March 01, 2017, 08:23:45 am »
Most definitely not a design error, though I agree the query word can be misleading.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus