 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Joe Aley Guest
|
Posted: Wed Jan 04, 2006 8:49 am Post subject: Mysql MultiThread Application |
|
|
Hi all...
I have searched a lot about multiple connection to a mysql database
using one form but never saw a sample code or something that could
guide me to.
So here goes my working code for one connection:
//------
...
SQLConnection,Connected := True;
SQLQuery := TSqlQuery.Create(nil);
SQLQuery.SQLConnection := SQLConnection;
SQLQuery.SQL.Add('Select * from mytable');
SQLQuery.open();
...
//------
Now, what do i have to change to see it working for multithreading?
I read something about TSession but seems sqlconnection does not have
this type...
Any help? I am using Delphi 7 & Mysql 5.0. Odbc most recent.
|
|
| Back to top |
|
 |
Guillem Guest
|
Posted: Wed Jan 04, 2006 4:05 pm Post subject: Re: Mysql MultiThread Application |
|
|
Joe Aley wrote:
| Quote: | Hi all...
I have searched a lot about multiple connection to a mysql database
using one form but never saw a sample code or something that could
guide me to.
So here goes my working code for one connection:
//------
...
SQLConnection,Connected := True;
SQLQuery := TSqlQuery.Create(nil);
SQLQuery.SQLConnection := SQLConnection;
SQLQuery.SQL.Add('Select * from mytable');
SQLQuery.open();
...
//------
Now, what do i have to change to see it working for multithreading?
I read something about TSession but seems sqlconnection does not have
this type...
Any help? I am using Delphi 7 & Mysql 5.0. Odbc most recent.
|
what are you trying to do multi-threaded? That the same instance of a
program executing uses various threads to connect simultaneously to
MySQL? Or that several instances of the same program connect
simultaneously?
--
Best regards :)
Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
--
Contribute to the Indy Docs project: http://docs.indyproject.org
--
In order to contact me remove the -nospam
|
|
| Back to top |
|
 |
Joe Aley Guest
|
Posted: Thu Jan 05, 2006 9:12 pm Post subject: Re: Mysql MultiThread Application |
|
|
Guillem wrote:
| Quote: | Joe Aley wrote:
Hi all...
I have searched a lot about multiple connection to a mysql database
using one form but never saw a sample code or something that could
guide me to.
So here goes my working code for one connection:
//------
...
SQLConnection,Connected := True;
SQLQuery := TSqlQuery.Create(nil);
SQLQuery.SQLConnection := SQLConnection;
SQLQuery.SQL.Add('Select * from mytable');
SQLQuery.open();
...
//------
Now, what do i have to change to see it working for multithreading?
I read something about TSession but seems sqlconnection does not have
this type...
Any help? I am using Delphi 7 & Mysql 5.0. Odbc most recent.
what are you trying to do multi-threaded? That the same instance of a
program executing uses various threads to connect simultaneously to
MySQL? Or that several instances of the same program connect
simultaneously?
|
I am doing a web server.
So, i droped IdHTTPServer on a Form and trying this code in ComandGet event.
I know how to do a critical section, but it does not solve the problem.
I need parallel connections.
|
|
| Back to top |
|
 |
Guillem Guest
|
Posted: Mon Jan 09, 2006 3:54 pm Post subject: Re: Mysql MultiThread Application |
|
|
Joe Aley wrote:
| Quote: | Guillem wrote:
Joe Aley wrote:
Hi all...
I have searched a lot about multiple connection to a mysql
database using one form but never saw a sample code or something
that could guide me to.
So here goes my working code for one connection:
//------
...
SQLConnection,Connected := True;
SQLQuery := TSqlQuery.Create(nil);
SQLQuery.SQLConnection := SQLConnection;
SQLQuery.SQL.Add('Select * from mytable');
SQLQuery.open();
...
//------
Now, what do i have to change to see it working for
multithreading? I read something about TSession but seems
sqlconnection does not have this type...
Any help? I am using Delphi 7 & Mysql 5.0. Odbc most recent.
what are you trying to do multi-threaded? That the same instance of
a program executing uses various threads to connect simultaneously
to MySQL? Or that several instances of the same program connect
simultaneously?
I am doing a web server.
So, i droped IdHTTPServer on a Form and trying this code in ComandGet
event.
I know how to do a critical section, but it does not solve the
problem. I need parallel connections.
|
Indy servers are multi-threaded. I do not know idHTTPServer but my
guess is (knowing how other Indy servers work) that it creates a thread
for each connection.
It seems to me your code is not thread-safe, as all threads would use
the same SQLConnection and SQLQuery. The problem surely lies there.
You can use different approaches to solve this problem. One could be to
use critical sections, but that is only a good idea if the protected
code section is a very fast one, which is usually not the case for
database operations.
A second approach could be to create a SQLConnection and a SQLQuery for
every thread and free them after.
3rd option would be to use connection pooling, but about this my
knowledge is too little to help you. Try googling on it
--
Best regards :)
Guillem Vicens Meier
Dep. Informatica Green Service S.A.
www.clubgreenoasis.com
--
Contribute to the Indy Docs project: http://docs.indyproject.org
--
In order to contact me remove the -nospam
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|