List:Commits« Previous MessageNext Message »
From:uwendel Date:May 29 2007 2:24pm
Subject:ODBC C-tests commit: r116 - trunk/testsuites/t_unixodbc_sap
View as plain text  
Added:
   trunk/testsuites/t_unixodbc_sap/sap_cola.c
Log:
Port of /unixODBC/tests/v3/conformance/Other/cola*


Added: trunk/testsuites/t_unixodbc_sap/sap_cola.c
===================================================================
--- trunk/testsuites/t_unixodbc_sap/sap_cola.c	2007-05-24 17:02:31 UTC (rev 115)
+++ trunk/testsuites/t_unixodbc_sap/sap_cola.c	2007-05-29 12:24:56 UTC (rev 116)
@@ -0,0 +1,66 @@
+#include "t_unixodbc_sap_suite.h"
+
+#define TABLE_ENGINE "InnoDB"
+
+/*
+  Use something 'large' here! Strictly speaking using 
+  malloc()/free() for a proper buffer would be better,
+  but this would require adding 'destructor' callbacks
+  to the OT_*-macro family and that's not worth it.
+  Table names will hopefully never become longer but 8k ...
+*/
+#define BUFFER_LENGTH 8192 + 1
+/*
+Ported SAP code: unixODBC/tests/v3/conformance/Other/cola
+*/
+OT_TEST_METHOD(sap_cola)
+{
+  SQLRETURN         ret;
+  SQLHANDLE         hdbc = get_dbc_handle();
+  SQLHANDLE         hstmt;
+  SQLCHAR           table_name[BUFFER_LENGTH];
+  SQLCHAR           table_name_prefix[BUFFER_LENGTH];
+  SQLCHAR           sql[BUFFER_LENGTH + 400];
+  SQLUSMALLINT      max_table_len;
+  SQLSMALLINT       out_len;
+  SQLCHAR           column_attribute[BUFFER_LENGTH];
+  SQLINTEGER        column_num_attr;
+
+  CHECK_SQL(ret = SQLGetInfo(hdbc, SQL_MAX_TABLE_NAME_LEN, &max_table_len,
sizeof(max_table_len), &out_len), 
+            hdbc, SQL_HANDLE_DBC);
+  OT_ASSERT_INT_MSG("SQLGetInfo()", SQL_SUCCESS, ret);
+  OT_ASSERT_MSG("Increate BUFFER_LENGTH and see the code comment", BUFFER_LENGTH >
max_table_len);
+
+  OT_ASSERT(sizeof(table_name_prefix) > sizeof((SQLCHAR*)"nixnutz"));
+  memcpy(table_name_prefix, (SQLCHAR*)"nixnutz", sizeof((SQLCHAR*)"nixnutz"));
+  unixodbc_sap_create_identifier((char*)table_name, (char*)table_name_prefix, (unsigned
int)max_table_len);
+
+  CHECK_SQL(ret = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt),
+            hdbc, SQL_HANDLE_DBC);
+  OT_ASSERT_INT_MSG("SQLAllocHandle()", SQL_SUCCESS, ret);
+
+  snprintf((char*)sql, sizeof(sql), "DROP TABLE IF EXISTS %s", table_name);
+  CHECK_SQL_S(SQLExecDirect(hstmt, sql, SQL_NTS), hstmt);
+  snprintf((char*)sql, sizeof(sql), "CREATE TABLE %s (col CHAR(10)) ENGINE = %s",
table_name, TABLE_ENGINE);
+  CHECK_SQL_S(SQLExecDirect(hstmt, sql, SQL_NTS), hstmt);
+  CHECK_SQL_S(SQLFreeStmt(hstmt, SQL_CLOSE), hstmt);
+
+  snprintf((char*)sql, sizeof(sql), "SELECT * FROM %s", table_name);
+  CHECK_SQL_S(SQLExecDirect(hstmt, sql, SQL_NTS), hstmt);
+  /*
+    I've no clue why the original code does this. Maybe it's because
+    SQL_MAX_TABLE_NAME_LEN was used like SQL_MAX_COLUMN_NAME and the
+    idea was to check the column name? Don't know. As SQLColAttributes()
+    is deprecated anyway, I fetch the table name...
+  */
+  CHECK_SQL_S(SQLColAttribute(hstmt, 1, SQL_DESC_BASE_TABLE_NAME, column_attribute,
sizeof(column_attribute), &out_len, &column_num_attr), hstmt);
+  OT_ASSERT(out_len > 0);
+  SAP_ASSERT_STRCMP(column_attribute, table_name);
+  CHECK_SQL_S(SQLColAttribute(hstmt, 1, SQL_DESC_BASE_COLUMN_NAME, column_attribute,
sizeof(column_attribute), &out_len, &column_num_attr), hstmt);
+  OT_ASSERT(out_len > 0);
+  SAP_ASSERT_STRCMP(column_attribute, "col");
+
+
+
+  CHECK_SQL_S(SQLFreeHandle(SQL_HANDLE_STMT, hstmt), hstmt);
+}

Thread
ODBC C-tests commit: r116 - trunk/testsuites/t_unixodbc_sapuwendel29 May