Hello!

I tried to insert one row to mysql database (ver. 3.23) via myodbc
(ver.2.50.39.00).
I made test program (vc6) which look like this:

#include <windows.h>
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>

int main(int argc, char* argv[])
{
  SQLSMALLINT     nCols;
  SQLHENV            m_SQLEnvironment;
  SQLHDBC            m_SQLConnection;
  SQLHSTMT          m_SQLStatement;
  SQLRETURN        iReturn;
  SQLCHAR            theNumeric2[50];
  SQLINTEGER       theNumeric3;
  SQLINTEGER       cbNumeric2;

  strcpy((char*)theNumeric2, "Jonson");
  cbNumeric2 = SQL_NTS;
  theNumeric3 = 12345;

  //Allocate Environment Handle
  iReturn = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE,
&m_SQLEnvironment);
  //Set environment to ODBC_3
  iReturn = SQLSetEnvAttr(m_SQLEnvironment, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3, 0);
  //Allocate connection handle
  iReturn = SQLAllocHandle(SQL_HANDLE_DBC, m_SQLEnvironment,
&m_SQLConnection);
  //Connect to the database.
  iReturn = SQLConnect(m_SQLConnection, (SQLCHAR*)"xxxxxxxxxxxx", 11,
(SQLCHAR*)"xxxxxxxx", 8, (SQLCHAR*)"xxxxxxxxxxx", 10);
  //Allocate the statement handle
  iReturn = SQLAllocHandle(SQL_HANDLE_STMT, m_SQLConnection,
&m_SQLStatement);
  iReturn = SQLPrepare(m_SQLStatement, (unsigned char*)"INSERT INTO
user_customers (user_id,user_surname, user_firstname) Values (?,?, 'Jon')",
SQL_NTS);
  /* do the binding for parameter 1, id */ 
  iReturn = SQLBindParameter(m_SQLStatement, 1, SQL_PARAM_INPUT,
SQL_C_SLONG, SQL_INTEGER, 0, 0, &theNumeric3, 6, &cbNumeric2);          
  /* Now do the bindings for parameter 2, name */ 
  iReturn = SQLBindParameter(m_SQLStatement, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_VARCHAR, 50, 0, theNumeric2, 7, &cbNumeric2);
  iReturn = SQLNumResultCols( m_SQLStatement, &nCols);
  iReturn = SQLExecute(m_SQLStatement); 
  /* Free param buffer resources */ 
  iReturn = SQLFreeStmt(m_SQLStatement, SQL_RESET_PARAMS); 
  return 1;
}

It works fine except it insert that row in database twice (first time when
SQLNumResultCols function is called and second when SQLExecute is called)
I tried this program in win2000 platform.
It look like if I do not use binding it works fine.
Is this bug or what?

-Mika-




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to