If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > ODBC + C + MySQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-04, 12:54
sleepymish sleepymish is offline
Registered User
 
Join Date: Jan 2004
Posts: 7
Red face ODBC + C + MySQL

Hi,

I'm new to the database and ODBC world and I have a question.
When I run the following code I get the error below. I googled and searched around, which said my connection might be lost or my query is too big. But neither of those cases are true. I'm wondering if anyone can find the mistake in my code.

THANKS!!!

Michelle



*************** ERROR ***********************************
mainSQLState HY000
MySQL server has gone away
*************** ERROR ***********************************




*************** CODE BEGINS******************************
// Insert Query
void cDatabase::Insert(void)
{
SQLRETURN rc = SQL_SUCCESS;

// used for SQLGetDiagRec
SQLINTEGER NativeError;
SQLCHAR SQLState[6];
SQLCHAR ErrorMsg[255];
SQLSMALLINT ErrorMsgLength;

// query statement
SQLCHAR* statement = (SQLCHAR*)"Insert into dummy values ('2004-01-09')";

// allocate a SQL statement handle
rc = SQLAllocHandle(SQL_HANDLE_STMT, m_hDbc, &m_hStmt);
printf("allocating SQL statement handle\n");

if (rc == SQL_SUCCESS)
{
// rc=SQLPrepare(m_hStmt, statement, 39);
rc=SQLExecDirect(m_hStmt, statement, SQL_NTS);

// rc=SQLExecute(m_hStmt);

if (rc == SQL_SUCCESS)
printf("insert successful!\n");
if (rc == SQL_ERROR)
{
printf("insert unsuccessful! Error!\n");
SQLGetDiagRec(SQL_HANDLE_STMT, m_hStmt, 1, SQLState, &NativeError, ErrorMsg, 255, &ErrorMsgLength);
printf("mainSQLState %s\n", SQLState);
printf("%s\n\n", ErrorMsg);
}
}
}

*************** CODE ENDS******************************
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On