Recent

Author Topic: Connecting to mariadb  (Read 13081 times)

jshand2010

  • Full Member
  • ***
  • Posts: 236
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.
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Connecting to mariadb
« Reply #1 on: February 24, 2017, 08:41:23 am »
What error?
Piece of code instead of whole project?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

jshand2010

  • Full Member
  • ***
  • Posts: 236
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
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
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 »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

jshand2010

  • Full Member
  • ***
  • Posts: 236
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
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

jshand2010

  • Full Member
  • ***
  • Posts: 236
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;   
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

rvk

  • Hero Member
  • *****
  • Posts: 6169
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: 1131
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 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
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 »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

rvk

  • Hero Member
  • *****
  • Posts: 6169
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: 1131
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 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Thaddy

  • Hero Member
  • *****
  • Posts: 14382
  • Sensorship about opinions does not belong here.
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 »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
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 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
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 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

balazsszekely

  • Guest
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.

 

TinyPortal © 2005-2018