mysql, c++, arx

mysql, c++, arx

Anonymous
Not applicable
554 Views
6 Replies
Message 1 of 7

mysql, c++, arx

Anonymous
Not applicable
I am trying to integrate my drawing package (arx) with mysql in realtime.
As of now I store a lot of data in attributes. This can make the drawing
files very large. Does anybody know of a way to connect to a mysql database
with vc++ 7.0.

Any help is greatly appreciated.

Thanks in advance.

Rob
0 Likes
555 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
This is the code I am currently working with. 
I can connect the database but I get errors when I try to query the
database:


size=2>
 

CString ConnectionString;

ConnectionString = "ODBC;DRIVER={MySQL ODBC 3.51
Driver};SERVER=localhost;DATABASE=dccad;USER=root;DSN=myodbc3-test;";

try //connect to the
DataManager

{


color=#0000ff>if
(DataManager.Open(ConnectionString))

{

dc_log(logfile,"\nDataManager opened
successfully.");

}

}

catch(CDBException *pe)
//catch database errors

{

dc_log(logfile,"Database Error:
%s",pe->m_strError);

pe->Delete();

}

//now get the types

CRecordset rsTypes(&DataManager);

CString fieldname,convdesc,SQLText;

SQLText="\"SELECT type,description FROM
tabletype;\"";

dc_log(logfile,"SQLText =
%s",SQLText);

try

{


size=2>rsTypes.Open(CRecordset::snapshot,(SQLText));

dc_log(logfile, "QUERY OPENED
SUCCESSFULLY");


color=#0000ff>while
(!rsTypes.IsEOF())

{

rsTypes.GetFieldValue(0,fieldname);

rsTypes.GetFieldValue(4,convdesc);

dc_log(logfile,"\nType: %s -
%s",fieldname,convdesc);

rsTypes.MoveNext();

}

}

catch (CDBException
*pe)

{

dc_log(logfile,"Query Error:
%s",pe->m_strError);

pe->Delete();

}
0 Likes
Message 3 of 7

Anonymous
Not applicable
Could there be problem with your SQLText. Why do
you need to include enclosing doubleQuote (the characters \") and why do you
have semicolon at the end? Should it be:


     
SQLText="SELECT type,description FROM tabletype";

 

If MySQL's ODBC complies with ODBC standard,
then the format of the SQL statement should be the same with other
database-ODBC's SQL statement. I have never used MySQL so I could be
wrong.

 

 

OutlookExpress' Question:

   If I want my reply to be in plainText,
what do I need to do? Rob's posting is in HTML, but I want my reply in
plainText.

 

Joseph


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

This is the code I am currently working
with.  I can connect the database but I get errors when I try to query
the database:


size=2>
 

CString ConnectionString;

ConnectionString = "ODBC;DRIVER={MySQL ODBC 3.51
Driver};SERVER=localhost;DATABASE=dccad;USER=root;DSN=myodbc3-test;";

try //connect to the
DataManager

{


color=#0000ff>if
(DataManager.Open(ConnectionString))

{

dc_log(logfile,"\nDataManager opened
successfully.");

}

}

catch(CDBException
*pe) //catch database errors

{

dc_log(logfile,"Database Error:
%s",pe->m_strError);

pe->Delete();

}

//now get the types

CRecordset
rsTypes(&DataManager);

CString fieldname,convdesc,SQLText;

SQLText="\"SELECT type,description FROM
tabletype;\"";

dc_log(logfile,"SQLText =
%s",SQLText);

try

{


size=2>rsTypes.Open(CRecordset::snapshot,(SQLText));

dc_log(logfile, "QUERY OPENED
SUCCESSFULLY");


color=#0000ff>while
(!rsTypes.IsEOF())

{

rsTypes.GetFieldValue(0,fieldname);

rsTypes.GetFieldValue(4,convdesc);

dc_log(logfile,"\nType: %s -
%s",fieldname,convdesc);

rsTypes.MoveNext();

}

}

catch (CDBException
*pe)

{

dc_log(logfile,"Query Error:
%s",pe->m_strError);

pe->Delete();

}
0 Likes
Message 4 of 7

Anonymous
Not applicable
Joseph,

 

I have tried many different syntaxes for the
sql. I even tried to enclose tabletype in single quotes as if it were a
string value.  When I do that I get an error logged to the file to check my
sql, so I know that I am connected to the sql server.

 

This is the error I get with my code: (from the log
file)

 

    DataManager opened
successfully.
    SQLText = "SELECT Type, Description FROM
tabletype;"
    Query Error: Attempt to open a table failed -
there were no columns to retrieve
    were
specified.

 

When I change the sytnax of the SQL I still get the
error but it seems that I am

not catching the CDBException
error......here is the log:

 

    DataManager opened
successfully.
    SQLText = SELECT Type, Description FROM
tabletype
    Query Error:

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Could there be problem with your SQLText. Why do
you need to include enclosing doubleQuote (the characters \") and why do you
have semicolon at the end? Should it be:


     
SQLText="SELECT type,description FROM tabletype";

 

If MySQL's ODBC complies with ODBC standard,
then the format of the SQL statement should be the same with other
database-ODBC's SQL statement. I have never used MySQL so I could be
wrong.

 

 

OutlookExpress' Question:

   If I want my reply to be in
plainText, what do I need to do? Rob's posting is in HTML, but I want my reply
in plainText.

 

Joseph


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

This is the code I am currently working
with.  I can connect the database but I get errors when I try to query
the database:


size=2>
 

CString ConnectionString;

ConnectionString = "ODBC;DRIVER={MySQL ODBC
3.51
Driver};SERVER=localhost;DATABASE=dccad;USER=root;DSN=myodbc3-test;";

try //connect to the
DataManager

{


color=#0000ff>if
(DataManager.Open(ConnectionString))

{

dc_log(logfile,"\nDataManager opened
successfully.");

}

}

catch(CDBException
*pe) //catch database errors

{

dc_log(logfile,"Database Error:
%s",pe->m_strError);

pe->Delete();

}

//now get the types

CRecordset
rsTypes(&DataManager);

CString
fieldname,convdesc,SQLText;

SQLText="\"SELECT type,description FROM
tabletype;\"";

dc_log(logfile,"SQLText =
%s",SQLText);

try

{


size=2>rsTypes.Open(CRecordset::snapshot,(SQLText));

dc_log(logfile, "QUERY OPENED
SUCCESSFULLY");


color=#0000ff>while
(!rsTypes.IsEOF())

{


size=2>rsTypes.GetFieldValue(0,fieldname);

rsTypes.GetFieldValue(4,convdesc);

dc_log(logfile,"\nType: %s -
%s",fieldname,convdesc);

rsTypes.MoveNext();

}

}

catch (CDBException
*pe)

{

dc_log(logfile,"Query Error:
%s",pe->m_strError);

pe->Delete();


size=2>}
0 Likes
Message 5 of 7

Anonymous
Not applicable
Rob,

  After rereading your original posting, you
said you are using VC++7. I have never used VC++7 so I don't think I might be
any help to you.

 

Just trying my best to help here. Why did you
mention " ... I am connected to the sql server...". Are you trying to
connect to MySQL or Microsoft SQLServer? Your ODBC driver you used in your code
is for MySQL.

CRecordSet throws 2 exception objects. Can you try
to catch the other one and check the description?

Are you sure you are connecting to the database you
intended? and If yes, does your database has the table and the columns mentioned
in your SQL statement?

Can you try using your original SQLStatement, but
delete the semicolon after string tabletype?

Can you also try SELECT * FROM
tabletype?

 

According to my MSDN Help, CRecordSet::Open(), it
said that no whitespace is allowed before the keyword SELECT.

 

Joseph


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Joseph,

 

I have tried many different syntaxes for the
sql. I even tried to enclose tabletype in single quotes as if it were a
string value.  When I do that I get an error logged to the file to check
my sql, so I know that I am connected to the sql server.

 

This is the error I get with my code: (from the
log file)

 

    DataManager opened
successfully.
    SQLText = "SELECT Type, Description FROM
tabletype;"
    Query Error: Attempt to open a table failed
- there were no columns to retrieve
    were
specified.

 

When I change the sytnax of the SQL I still get
the error but it seems that I am

not catching the CDBException
error......here is the log:

 

    DataManager opened
successfully.
    SQLText = SELECT Type, Description FROM
tabletype
    Query Error:

 

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Could there be problem with your SQLText. Why
do you need to include enclosing doubleQuote (the characters \") and why do
you have semicolon at the end? Should it be:


     
SQLText="SELECT type,description FROM tabletype";

 

If MySQL's ODBC complies with ODBC
standard, then the format of the SQL statement should be the same with other
database-ODBC's SQL statement. I have never used MySQL so I could be
wrong.

 

 

OutlookExpress' Question:

   If I want my reply to be in
plainText, what do I need to do? Rob's posting is in HTML, but I want my
reply in plainText.

 

Joseph


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

This is the code I am currently working
with.  I can connect the database but I get errors when I try to
query the database:


size=2>
 

CString ConnectionString;

ConnectionString = "ODBC;DRIVER={MySQL ODBC
3.51
Driver};SERVER=localhost;DATABASE=dccad;USER=root;DSN=myodbc3-test;";

try //connect to the
DataManager

{


color=#0000ff>if
(DataManager.Open(ConnectionString))

{

dc_log(logfile,"\nDataManager opened
successfully.");

}

}

catch(CDBException
*pe) //catch database errors

{

dc_log(logfile,"Database Error:
%s",pe->m_strError);

pe->Delete();

}

//now get the
types

CRecordset
rsTypes(&DataManager);

CString
fieldname,convdesc,SQLText;

SQLText="\"SELECT type,description FROM
tabletype;\"";

dc_log(logfile,"SQLText =
%s",SQLText);

try

{


size=2>rsTypes.Open(CRecordset::snapshot,(SQLText));

dc_log(logfile, "QUERY OPENED
SUCCESSFULLY");


color=#0000ff>while
(!rsTypes.IsEOF())

{


size=2>rsTypes.GetFieldValue(0,fieldname);


size=2>rsTypes.GetFieldValue(4,convdesc);

dc_log(logfile,"\nType: %s -
%s",fieldname,convdesc);

rsTypes.MoveNext();

}

}

catch
(CDBException *pe)

{

dc_log(logfile,"Query Error:
%s",pe->m_strError);

pe->Delete();


size=2>}
0 Likes
Message 6 of 7

Anonymous
Not applicable
Hi, Joseph!
=========Beginning of the citation==============
OutlookExpress' Question:
If I want my reply to be in plainText, what do I need to do? Rob's
posting is in HTML, but I want my reply in plainText.
=========The end of the citation================
You can set Plain text in menu Format of Outlook Express.

--
Best Regards,
Alexander Rivilis
0 Likes
Message 7 of 7

Anonymous
Not applicable
Thanx Alex,
to add, have to uncheck "Reply to messages using the format in which they
were sent".

Joseph

"Alexander Rivilis" wrote in message
news:6FD330B94ADEC1200A03F644391512F0@in.WebX.maYIadrTaRb...
> Hi, Joseph!
> =========Beginning of the citation==============
> OutlookExpress' Question:
> If I want my reply to be in plainText, what do I need to do? Rob's
> posting is in HTML, but I want my reply in plainText.
> =========The end of the citation================
> You can set Plain text in menu Format of Outlook Express.
>
> --
> Best Regards,
> Alexander Rivilis
>
>
>
0 Likes