List:Commits« Previous MessageNext Message »
From:bdegtyariov Date:October 5 2007 4:12pm
Subject:Connector/ODBC 3.51 commit: r807 - in trunk: . driver test
View as plain text  
Modified:
   trunk/ChangeLog
   trunk/driver/execute.c
   trunk/test/my_result.c
Log:
Fixed SQLSetPos that generated incorrect INSERT statement for result columns without bound
data buffers. (Bug #31246)


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-10-05 16:06:38 UTC (rev 806)
+++ trunk/ChangeLog	2007-10-05 16:12:19 UTC (rev 807)
@@ -14,6 +14,8 @@
   * Fixed incorrect input requirement in the setup dialog. (Bug #30499)
   * Added SQLSetParam function and fixed handling of buffer length in
     SQLBindParameter. (Bug #29871)
+  * Fixed SQLSetPos that generated incorrect INSERT statement for result
+    columns without bound data buffers. (Bug #31246)
 
 ----
 

Modified: trunk/driver/execute.c
===================================================================
--- trunk/driver/execute.c	2007-10-05 16:06:38 UTC (rev 806)
+++ trunk/driver/execute.c	2007-10-05 16:12:19 UTC (rev 807)
@@ -293,8 +293,12 @@
       We may see SQL_COLUMN_IGNORE from bulk INSERT operations, where we
       may have been told to ignore a column in one particular row. So we
       try to insert DEFAULT, or NULL for really old servers.
+      In case there are less parameters than result columns we have to
+      insert NULL or DEFAULT.
     */
-    else if ( *(param->actual_len) == SQL_COLUMN_IGNORE )
+    else if (*(param->actual_len) == SQL_COLUMN_IGNORE ||
+             (*(param->actual_len) == 0 && param->CType == 0 && 
+              param->buffer == NULL))
     {
       if (is_minimum_version(dbc->mysql.server_version, "4.0.3", 5))
         return add_to_buffer(net,to,"DEFAULT",7);

Modified: trunk/test/my_result.c
===================================================================
--- trunk/test/my_result.c	2007-10-05 16:06:38 UTC (rev 806)
+++ trunk/test/my_result.c	2007-10-05 16:12:19 UTC (rev 807)
@@ -1854,6 +1854,56 @@
 }
 
 
+DECLARE_TEST(t_bug31246)
+{
+  SQLSMALLINT ncol;
+  SQLCHAR     *buf = "Key1";
+  SQLCHAR     field1[20];
+  SQLINTEGER  field2;
+  SQLCHAR     field3[20];
+  SQLRETURN   rc;
+  
+  ok_sql(hstmt, "DROP TABLE IF EXISTS t_bug31246");
+  ok_sql(hstmt, "CREATE TABLE t_bug31246 ("
+                "field1 VARCHAR(50) NOT NULL PRIMARY KEY, "
+                "field2 int DEFAULT 10, "
+                "field3 VARCHAR(50) DEFAULT \"Default Text\")");
+
+  /* No need to insert any rows in the table, so do SELECT */
+  ok_sql(hstmt, "SELECT * FROM t_bug31246");
+  ok_stmt(hstmt, SQLNumResultCols(hstmt,&ncol));
+  is_num(ncol, 3);
+
+  /* Bind only one column instead of three ones */
+  ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_CHAR, buf, strlen(buf), NULL));
+
+  /* Expect SQL_NO_DATA_FOUND result from the empty table */
+  rc= SQLExtendedFetch(hstmt, SQL_FETCH_NEXT, 1, NULL, NULL);
+  is_num(rc, SQL_NO_DATA_FOUND);
+
+  /* Here was the problem */
+  ok_stmt(hstmt, SQLSetPos(hstmt, 1, SQL_ADD, SQL_LOCK_NO_CHANGE));
+
+  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_UNBIND));
+  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
+
+  /* Check whether the row was inserted with the default values*/
+  ok_sql(hstmt, "SELECT * FROM t_bug31246 WHERE field1=\"Key1\"");
+  ok_stmt(hstmt, SQLBindCol(hstmt, 1, SQL_C_CHAR, field1, 
+          sizeof(field1), NULL));
+  ok_stmt(hstmt, SQLBindCol(hstmt, 2, SQL_C_LONG, &field2, 
+          sizeof(SQLINTEGER), NULL));
+  ok_stmt(hstmt, SQLBindCol(hstmt, 3, SQL_C_CHAR, field3, 
+          sizeof(field3), NULL));
+  ok_stmt(hstmt, SQLFetch(hstmt));
+  
+  /* Clean-up */
+  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
+  ok_sql(hstmt, "DROP TABLE t_bug31246");
+  return OK;
+}
+
+
 BEGIN_TESTS
   ADD_TEST(my_resultset)
   ADD_TEST(t_convert_type)
@@ -1878,6 +1928,7 @@
   ADD_TEST(t_binary_collation)
   ADD_TODO(t_bug29239)
   ADD_TODO(t_bug30958)
+  ADD_TODO(t_bug31246)
 END_TESTS
 
 

Thread
Connector/ODBC 3.51 commit: r807 - in trunk: . driver testbdegtyariov5 Oct