-
June 5th, 2006, 06:31 AM
#1
MySQL Driver Connect
Hi you all
I am using Visual C++ to access a MySQL database. I am using the ODBC connector, and CRecordSet class from the MFC.
I have included into a DLL all my accesses to the database, wrapping them with functions more or less like this.
__DATAACCESS_API__ int get_meter2_data(meter2_t& meter2_data)
{
TRY {
CTableMeter2 oTableMeter2;
if (oTableMeter2.Open() == 0) {
return -1;
}
if (oTableMeter2.GetRecordCount() == 0) {
oTableMeter2.Close();
return -1;
}
oTableMeter2.MoveFirst();
meter2_data.sn = oTableMeter2.m_meter_sn;
meter2_data.cct_sn = oTableMeter2.m_cct_sn;
oTableMeter2.Close();
} CATCH(CDBException, e) {
return -1;
} END_CATCH
return 0;
}
My problem is that most of the time these functions work, but sometimes it is displayed the "Connector ODBC Driver Connect" screen (with correct values).
I can accept the values and the application continues working, but...
All help is wellcome.
Thanks.
Miguel Ángel
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
-
June 5th, 2006, 07:13 AM
#2
Re: MySQL Driver Connect
What you are expiriencing is probably a ODBC fault when it can't connect to MySQL base, try to catch it in exeption and then try to recconect again. If the proble persist I would recomend then you start using MySQL c-API provided with all MySQL implementation, It Is very good and it is pretty low level so it is up to you to design wrappers any way you want. Also I will presume that you will have problems with ODBC when trying to execute stored procedures and triggrers.
You just divided by zero, didn't you?
-
June 5th, 2006, 10:29 AM
#3
Re: MySQL Driver Connect
Yes... I understand that the correct way to solve the problem would be in a try... catch.
Am I doing it wrong in my previous code?
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
-
June 5th, 2006, 12:10 PM
#4
Re: MySQL Driver Connect
Please use code tags [code] [/code]
We would change the world, but God won't give us the sourcecode..
Undocumented futures are fun and useful....
_________
Gili
-
June 5th, 2006, 12:31 PM
#5
Re: MySQL Driver Connect
In other case I would have take into account the idea of this wrapper. However in this case I have no much time to get the solution (I will do a remake of the application next month, but at the moment...).
I am trying to use OpenEx instead of Open, and use the flag CDatabase::noOdbcDialog.
Do you consider it a good solution?
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
-
June 5th, 2006, 02:25 PM
#6
Re: MySQL Driver Connect
Hello
If you are using MySQL you might want to check that the tables are searchable
To do this the MyISAM is acceptable
Regards
"trampling out the vintage"
-
June 6th, 2006, 08:49 AM
#7
Re: MySQL Driver Connect
Sorry, but this is the first time that I work with a database. What is MYISAM?
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
-
June 6th, 2006, 08:51 AM
#8
Re: MySQL Driver Connect
Here is some reference
MYISAM
Please use code tags [code] [/code]
We would change the world, but God won't give us the sourcecode..
Undocumented futures are fun and useful....
_________
Gili
-
June 7th, 2006, 05:11 AM
#9
Re: MySQL Driver Connect
I have read something about MyISAM and InnoDB, and this last seems to be more reliable.
Am I wrong?
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
-
June 7th, 2006, 06:03 AM
#10
Re: MySQL Driver Connect
Originally Posted by Caronte
I have read something about MyISAM and InnoDB, and this last seems to be more reliable.
Yeah, that's because unlike MyISAM, InnoDB supports foreign keys and transactions.
But, AFAIK it costs more if you want to redistribute MySQL with your application.
-
June 7th, 2006, 06:12 AM
#11
Re: MySQL Driver Connect
I have tried a lot of things to solve my initial problem, but finally it seems that the problem is in using a query to open a table...
I mean... the dialog does not seem to appear whe I do someting like:
oTableMeter2.Open();
but appears when I do
char szQuery[SQUERY_SIZE];
wsprintf(szQuery, "SELECT * FROM contadores2 WHERE cct_sn=%lu AND meter_sn=%lu", cct_sn, meter_sn);
oTableMeter2.Open(CRecordset::snapshot, szQuery);
Thanks
Caronte
Si tiene solución... ¿por qué te preocupas?
Si no tiene solución... ¿por qué te preocupas?
-
June 7th, 2006, 06:12 AM
#12
Re: MySQL Driver Connect
Originally Posted by g_gili
I would like to recommend it also, not because is my article but first is much more faster than MFC ODBC classes, CDatabase, CRecordset and so on which are really, really slow.
Originally Posted by Caronte
In other case I would have take into account the idea of this wrapper. However in this case I have no much time to get the solution (I will do a remake of the application next month, but at the moment...).
IMO, it request less time to dig and implement than ODBC classes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|