Recent

Author Topic: SQL Connection insists on transaction?  (Read 1723 times)

HopefulGuy

  • New Member
  • *
  • Posts: 28
SQL Connection insists on transaction?
« on: May 10, 2021, 01:21:04 am »
I've looked, but perhaps I'm missing something but the TSQLConnection seems to be insisting I set a transaction, even for an initial read.

In the FormCreate() function, I have code like this (it's incomplete, but was setup for a quick test to ensure basic functionality):
     Db1Query.Sql.Add('Select IDNo, FirstName, FamilyName from Table1 order by IDNo');
     try
       begin
         Db1Query.Open;
         while not (Db1Query.EOF) do
              Db1Query.next; // just itterate through for now
       end;
     except
       on E: Exception do
       begin
         MessageDlg('Database Error!', 'An error occured while attempting to access the database. Error message received was: ' + E.Message, mtError, [mbClose], '');
         halt(1);
       end;

DB1query is a TSQLQuery with the host, password, username and database name assigned in the component properties, outside of any function while the SQL text is defined earlier than this block.

But as soon as I try running the program, I get an error about Transactions not being set. This is a test database with a whole TWO records. Now why would I use a transaction. And why would the system insist on that? Frankly, I don't think I'd ever use a transaction because this program is not meant for multi-user simultaneous use. So how do I get around this? I can put TSQLTransaction on there, but why? Why include a component that I'll NEVER use except for assigning it to a property of some other component?  The Attached image shows the dialog.
« Last Edit: May 10, 2021, 01:37:47 am by HopefulGuy »

dsiders

  • Sr. Member
  • ****
  • Posts: 496
Lazarus 2.0.12, 2.2.0-RC1, 2.3 (SVN) / FPC 3.2.0, 3.2.2 / x86-win64 / Windows 8.1

HopefulGuy

  • New Member
  • *
  • Posts: 28
Re: SQL Connection insists on transaction?
« Reply #2 on: May 10, 2021, 03:57:53 am »
 I did read those. They explain what a Transaction is used for. What I was trying to determine is why it is forcing transaction mode on me. Transactions are handy for more busy systems, don't get me wrong. But this is a personal project, one user/access at a time. Never more than that. So transactions are nothing more than wasted CPU power and wasted bandwidth in this case. So maybe I should have asked if anyone knows why there is no way to force non-transaction mode.

egsuh

  • Hero Member
  • *****
  • Posts: 792
Re: SQL Connection insists on transaction?
« Reply #3 on: May 10, 2021, 11:21:33 am »
Transaction is required by database server, not by local application. Most SQL databases require transactions. If you are using dBase or MS Access then transactions are not necessary.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3207
  • Compiler Developer
Re: SQL Connection insists on transaction?
« Reply #4 on: May 10, 2021, 01:05:14 pm »
I did read those. They explain what a Transaction is used for. What I was trying to determine is why it is forcing transaction mode on me. Transactions are handy for more busy systems, don't get me wrong. But this is a personal project, one user/access at a time. Never more than that. So transactions are nothing more than wasted CPU power and wasted bandwidth in this case. So maybe I should have asked if anyone knows why there is no way to force non-transaction mode.

FPC's SQL-DB always requires a transaction. That is simply how it is designed. This might or might not be translated to a server side transaction depending on the DB.

Transaction is required by database server, not by local application. Most SQL databases require transactions. If you are using dBase or MS Access then transactions are not necessary.

Not quite right: a TSQLTransaction instance is required by TSQLQuery due to how the system is designed.

dseligo

  • Sr. Member
  • ****
  • Posts: 318
Re: SQL Connection insists on transaction?
« Reply #5 on: May 10, 2021, 01:17:28 pm »
You can use ZeosDBO database components. In ZeosDBO using transactions for MySQL and MariaDB is not mandatory. I use transactions explicitly when I want to use them.
You can install ZeosDBO through Online Package Manager.

Zoran

  • Hero Member
  • *****
  • Posts: 1671
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: SQL Connection insists on transaction?
« Reply #6 on: May 10, 2021, 01:46:55 pm »
You can use ZeosDBO database components. In ZeosDBO using transactions for MySQL and MariaDB is not mandatory. I use transactions explicitly when I want to use them.
You can install ZeosDBO through Online Package Manager.

It is just the way how Zeos is designed -- one connection always create one transaction which it holds internally. It's essentially no different than having one connection object and one transaction object in SQLdb.

As PascalDragon wrote, the transaction might not map to a server side transaction when working with some simple db engines, which do not always require transaction.

I believe it falls to very similar approach, with either Zeos, where connection and transaction are packed in one component, or SQLdb, where you need two separate components.

 

TinyPortal © 2005-2018