List:Commits« Previous MessageNext Message »
From:jwinstead Date:May 2 2007 4:53pm
Subject:Connector/ODBC 3.51 commit: r373 - in trunk/test: . include
View as plain text  
Modified:
   trunk/test/include/odbctap.h
   trunk/test/my_cursor.c
Log:
Convert tmysql_pos_update_ex to odbctap in my_cursor.
Clean up some of the odbctap macros to avoid confusion on variable names


Modified: trunk/test/include/odbctap.h
===================================================================
--- trunk/test/include/odbctap.h	2007-05-02 16:01:19 UTC (rev 372)
+++ trunk/test/include/odbctap.h	2007-05-02 16:53:05 UTC (rev 373)
@@ -155,13 +155,13 @@
   Execute an SQL statement and bail out if the execution does not return
   SQL_SUCCESS or SQL_SUCCESS_WITH_INFO.
 
-  @param hstmt Handle for statement object
-  @param query The query to execute
+  @param statement Handle for statement object
+  @param query     The query to execute
 */
-#define ok_sql(hstmt, query) \
+#define ok_sql(statement, query) \
 do { \
-  SQLRETURN rc= SQLExecDirect(hstmt, (SQLCHAR *)query, SQL_NTS); \
-  print_diag(rc, SQL_HANDLE_STMT, hstmt, \
+  SQLRETURN rc= SQLExecDirect((statement), (SQLCHAR *)(query), SQL_NTS); \
+  print_diag(rc, SQL_HANDLE_STMT, (statement), \
              "SQLExecDirect(hstmt, \"" query "\", SQL_NTS)",\
              __FILE__, __LINE__); \
   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) \
@@ -173,17 +173,17 @@
   Verify that the result of an SQL statement call matches an expected
   result, such as SQL_ERROR.
 
-  @param hstmt  Handle for statement object
-  @param query  The query to execute
-  @param expect The expected result
+  @param statement Handle for statement object
+  @param query     The query to execute
+  @param expect    The expected result
 */
-#define expect_sql(hstmt, query, expect) \
+#define expect_sql(statement, query, expect) \
 do { \
-  SQLRETURN rc= SQLExecDirect(hstmt, (SQLCHAR *)query, SQL_NTS); \
-  if (rc != expect) \
+  SQLRETURN rc= SQLExecDirect((statement), (SQLCHAR *)(query), SQL_NTS); \
+  if (rc != (expect)) \
   { \
-    print_diag(rc, SQL_HANDLE_STMT, hstmt, \
-               "SQLExecDirect(hstmt, \"" query "\", SQL_NTS)",\
+    print_diag(rc, SQL_HANDLE_STMT, (statement), \
+               "SQLExecDirect(" #statement ", \"" query "\", SQL_NTS)",\
                __FILE__, __LINE__); \
     printf("# Expected %d, but got %d in %s on line %d\n", expect, rc, \
            __FILE__, __LINE__); \
@@ -196,13 +196,13 @@
   Verify that the results of an ODBC function call on a statement handle was
   SQL_SUCCESS or SQL_SUCCESS_WITH_INFO.
 
-  @param hstmt Handle for statement object
-  @param call  The function call
+  @param statement Handle for statement object
+  @param call      The function call
 */
-#define ok_stmt(hstmt, call) \
+#define ok_stmt(statement, call) \
 do { \
-  SQLRETURN rc= call; \
-  print_diag(rc, SQL_HANDLE_STMT, hstmt, #call, __FILE__, __LINE__); \
+  SQLRETURN rc= (call); \
+  print_diag(rc, SQL_HANDLE_STMT, (statement), #call, __FILE__, __LINE__); \
   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) \
     return FAIL; \
 } while (0)
@@ -216,7 +216,7 @@
 */
 #define nok_pass_on(call) \
 do { \
-  int rc= call; \
+  int rc= (call); \
   if (rc != OK) \
     return rc; \
 } while (0)
@@ -226,17 +226,17 @@
   Verify that the result of an ODBC function call matches an expected
   result, such as SQL_NO_DATA_FOUND.
 
-  @param hstmt  Handle for statement object
-  @param call   The function call
-  @param expect The expected result
+  @param statement Handle for statement object
+  @param call      The function call
+  @param expect    The expected result
 */
-#define expect_stmt(hstmt, call, expect) \
+#define expect_stmt(statement, call, expect) \
 do { \
-  SQLRETURN rc= call; \
-  if (rc != expect) \
+  SQLRETURN rc= (call); \
+  if (rc != (expect)) \
   { \
-    print_diag(rc, SQL_HANDLE_STMT, hstmt, #call, __FILE__, __LINE__); \
-    printf("# Expected %d, but got %d in %s on line %d\n", expect, rc, \
+    print_diag(rc, SQL_HANDLE_STMT, (statement), #call, __FILE__, __LINE__); \
+    printf("# Expected %d, but got %d in %s on line %d\n", (expect), rc, \
            __FILE__, __LINE__); \
     return FAIL; \
   } \
@@ -247,13 +247,13 @@
   Verify that the results of an ODBC function call on an environment handle
   was SQL_SUCCESS or SQL_SUCCESS_WITH_INFO.
 
-  @param henv  Handle for environment
-  @param call  The function call
+  @param environ Handle for environment
+  @param call    The function call
 */
-#define ok_env(henv, call) \
+#define ok_env(environ, call) \
 do { \
-  SQLRETURN rc= call; \
-  print_diag(rc, SQL_HANDLE_ENV, henv, #call, __FILE__, __LINE__); \
+  SQLRETURN rc= (call); \
+  print_diag(rc, SQL_HANDLE_ENV, (environ), #call, __FILE__, __LINE__); \
   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) \
     return FAIL; \
 } while (0)
@@ -263,13 +263,13 @@
   Verify that the results of an ODBC function call on a connection handle
   was SQL_SUCCESS or SQL_SUCCESS_WITH_INFO.
 
-  @param hdbc  Handle for database connection
+  @param con   Handle for database connection
   @param call  The function call
 */
-#define ok_con(hdbc, call) \
+#define ok_con(con, call) \
 do { \
-  SQLRETURN rc= call; \
-  print_diag(rc, SQL_HANDLE_DBC, hdbc, #call, __FILE__, __LINE__); \
+  SQLRETURN rc= (call); \
+  print_diag(rc, SQL_HANDLE_DBC, (con), #call, __FILE__, __LINE__); \
   if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) \
     return FAIL; \
 } while (0)
@@ -327,7 +327,7 @@
 
     /** @todo Handle multiple diagnostic records. */
     drc= SQLGetDiagRec(htype, handle, 1, sqlstate, &native_error,
-                                 message, SQL_MAX_MESSAGE_LENGTH - 1, &length);
+                       message, SQL_MAX_MESSAGE_LENGTH - 1, &length);
 
     if (SQL_SUCCEEDED(drc))
       printf("# [%6s] %*s in %s on line %d\n",

Modified: trunk/test/my_cursor.c
===================================================================
--- trunk/test/my_cursor.c	2007-05-02 16:01:19 UTC (rev 372)
+++ trunk/test/my_cursor.c	2007-05-02 16:53:05 UTC (rev 373)
@@ -1583,80 +1583,58 @@
 
 DECLARE_TEST(tmysql_pos_update_ex)
 {
-    SQLRETURN rc;
-    SQLHSTMT hstmt1;
-    SQLUINTEGER pcrow;
-    SQLUSMALLINT rgfRowStatus;
-    SQLCHAR cursor[30],sql[100],data[]="updated";
+  SQLHSTMT hstmt1;
+  SQLUINTEGER pcrow;
+  SQLUSMALLINT rgfRowStatus;
+  SQLCHAR cursor[30], sql[255], data[]= "tmysql_pos_update_ex";
 
-    rc = SQLAllocStmt(hdbc,&hstmt1);
-    mycon(hdbc,rc);
+  ok_sql(hstmt, "DROP TABLE IF EXISTS t_pos_updex");
+  ok_sql(hstmt, "CREATE TABLE t_pos_updex (a INT PRIMARY KEY, b VARCHAR(30))");
+  ok_sql(hstmt, "INSERT INTO t_pos_updex VALUES (100,'venu'),(200,'MySQL')");
 
-    tmysql_exec(hstmt,"drop table t_pos_updex");
-    rc = tmysql_exec(hstmt,"create table t_pos_updex(col1 int NOT NULL primary key, col2
varchar(30))");
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
 
-    rc = tmysql_exec(hstmt,"insert into t_pos_updex values(100,'venu')");
-    mystmt(hstmt,rc);
+  ok_sql(hstmt, "SELECT * FROM t_pos_updex");
 
-    rc = tmysql_exec(hstmt,"insert into t_pos_updex values(200,'MySQL')");
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt, SQLExtendedFetch(hstmt, SQL_FETCH_ABSOLUTE, 2,
+                                  &pcrow, &rgfRowStatus));
 
-    rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
-    mycon(hdbc,rc);
+  ok_stmt(hstmt, SQLSetPos(hstmt, 1, SQL_POSITION, SQL_LOCK_NO_CHANGE));
 
-    rc = SQLFreeStmt(hstmt,SQL_CLOSE);
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt, SQLGetCursorName(hstmt, cursor, sizeof(cursor), NULL));
 
-    rc = tmysql_exec(hstmt,"select * from t_pos_updex");
-    mystmt(hstmt,rc);
+  ok_con(hdbc, SQLAllocStmt(hdbc, &hstmt1));
 
-    rc = SQLExtendedFetch(hstmt,SQL_FETCH_ABSOLUTE,2,&pcrow,&rgfRowStatus);
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt1, SQLBindParameter(hstmt1, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
+                                   SQL_CHAR, 0, 0, data, sizeof(data), NULL));
 
-    rc = SQLSetPos(hstmt,1,SQL_POSITION,SQL_LOCK_NO_CHANGE);
-    mystmt(hstmt,rc);
+  sprintf((char *)sql,
+          "UPDATE t_pos_updex SET a = 999, b = ? WHERE CURRENT OF %s",
+          cursor);
 
-    rc = SQLBindParameter(hstmt1,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,0,0,data,20,NULL);
-    mystmt(hstmt1,rc);
+  ok_stmt(hstmt1, SQLExecDirect(hstmt1, sql, SQL_NTS));
 
-    rc = SQLGetCursorName(hstmt,cursor,30,NULL);
-    mystmt(hstmt,rc);
+  ok_stmt(hstmt1, SQLRowCount(hstmt1, &pcrow));
+  is_num(pcrow, 1);
 
-    sprintf(sql,"UPDATE t_pos_updex SET col1= 999, col2 = ? WHERE CURRENT OF %s",cursor);
+  ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_DROP));
 
-    rc = SQLExecDirect(hstmt1,sql,SQL_NTS);
-    mystmt(hstmt1,rc);
+  ok_stmt(hstmt, SQLFreeStmt(hstmt, SQL_CLOSE));
 
-    SQLNumResultCols(hstmt1,&rgfRowStatus);
+  ok_sql(hstmt, "SELECT * FROM t_pos_updex");
 
-    rc = SQLFreeStmt(hstmt,SQL_CLOSE);
-    rc = SQLFreeStmt(hstmt1,SQL_CLOSE);
+  ok_stmt(hstmt, SQLFetch(hstmt));
+  is_num(my_fetch_int(hstmt, 1), 100);
+  is_str(my_fetch_str(hstmt, sql, 2), "venu", 4);
 
-    rc = SQLTransact(NULL,hdbc,SQL_COMMIT);
-    mycon(hdbc,rc);
+  ok_stmt(hstmt, SQLFetch(hstmt));
+  is_num(my_fetch_int(hstmt, 1), 999);
+  is_str(my_fetch_str(hstmt, sql, 2), "tmysql_pos_update_ex", 20);
 
-    rc = tmysql_exec(hstmt,"select * from t_pos_updex");
-    mystmt(hstmt,rc);
+  expect_stmt(hstmt, SQLFetch(hstmt), SQL_NO_DATA_FOUND);
 
-    rc = SQLFetch(hstmt);
-    mystmt(hstmt,rc);
+  ok_sql(hstmt, "DROP TABLE IF EXISTS t_pos_updex");
 
-    rc = SQLFetch(hstmt);
-    mystmt(hstmt,rc);
-    {
-        SQLCHAR szData[20];
-        my_assert(999 == my_fetch_int(hstmt,1));
-        my_assert(!strcmp("updated",my_fetch_str(hstmt,szData,2)));
-    }
-
-    rc = SQLFreeStmt(hstmt,SQL_CLOSE);
-    mystmt(hstmt,rc);
-
-    SQLFreeStmt(hstmt1,SQL_RESET_PARAMS);
-    rc = SQLFreeStmt(hstmt1,SQL_DROP);
-    mystmt(hstmt1,rc);
-
   return OK;
 }
 

Thread
Connector/ODBC 3.51 commit: r373 - in trunk/test: . includejwinstead2 May