-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added regression test for DescRec functions
- Loading branch information
1 parent
78460ee
commit dcd388e
Showing
4 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
connected | ||
|
||
-- Column 1 -- | ||
SQL_DESC_NAME: col1 | ||
SQL_DESC_TYPE: 4 | ||
SQL_DESC_OCTET_LENGTH: 0 | ||
SQL_DESC_PRECISION: 0 | ||
SQL_DESC_SCALE: 0 | ||
SQL_DESC_NULLABLE: 0 | ||
|
||
-- Column 2 -- | ||
SQL_DESC_NAME: col2 | ||
SQL_DESC_TYPE: 2 | ||
SQL_DESC_OCTET_LENGTH: 6 | ||
SQL_DESC_PRECISION: 4 | ||
SQL_DESC_SCALE: 2 | ||
SQL_DESC_NULLABLE: 1 | ||
|
||
-- Column 3 -- | ||
SQL_DESC_NAME: col3 | ||
SQL_DESC_TYPE: 12 | ||
SQL_DESC_OCTET_LENGTH: 40 | ||
SQL_DESC_PRECISION: 0 | ||
SQL_DESC_SCALE: 0 | ||
SQL_DESC_NULLABLE: 0 | ||
|
||
-- Column 4 -- | ||
SQL_DESC_NAME: col4 | ||
SQL_DESC_TYPE: -5 | ||
SQL_DESC_OCTET_LENGTH: 8 | ||
SQL_DESC_PRECISION: 0 | ||
SQL_DESC_SCALE: 0 | ||
SQL_DESC_NULLABLE: 0 | ||
disconnecting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
connected | ||
|
||
-- Column 1 -- | ||
SQL_DESC_NAME: col1 | ||
SQL_DESC_TYPE: 4 | ||
SQL_DESC_OCTET_LENGTH: 0 | ||
SQL_DESC_PRECISION: 0 | ||
SQL_DESC_SCALE: 0 | ||
SQL_DESC_NULLABLE: 0 | ||
|
||
-- Column 2 -- | ||
SQL_DESC_NAME: col2 | ||
SQL_DESC_TYPE: 2 | ||
SQL_DESC_OCTET_LENGTH: 6 | ||
SQL_DESC_PRECISION: 4 | ||
SQL_DESC_SCALE: 2 | ||
SQL_DESC_NULLABLE: 1 | ||
|
||
-- Column 3 -- | ||
SQL_DESC_NAME: col3 | ||
SQL_DESC_TYPE: 12 | ||
SQL_DESC_OCTET_LENGTH: 20 | ||
SQL_DESC_PRECISION: 0 | ||
SQL_DESC_SCALE: 0 | ||
SQL_DESC_NULLABLE: 0 | ||
|
||
-- Column 4 -- | ||
SQL_DESC_NAME: col4 | ||
SQL_DESC_TYPE: -5 | ||
SQL_DESC_OCTET_LENGTH: 8 | ||
SQL_DESC_PRECISION: 0 | ||
SQL_DESC_SCALE: 0 | ||
SQL_DESC_NULLABLE: 0 | ||
disconnecting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "common.h" | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
SQLRETURN rc; | ||
HSTMT hstmt = SQL_NULL_HSTMT; | ||
SQLSMALLINT colcount; | ||
SQLHDESC hDesc; | ||
SQLCHAR name[64]; | ||
SQLSMALLINT nameLen = 64; | ||
SQLSMALLINT type, subType; | ||
SQLSMALLINT precision, scale, nullable; | ||
SQLLEN length; | ||
|
||
test_connect(); | ||
|
||
rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt); | ||
if (!SQL_SUCCEEDED(rc)) | ||
{ | ||
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn); | ||
exit(1); | ||
} | ||
|
||
/* Prepare a test table */ | ||
rc = SQLExecDirect(hstmt, (SQLCHAR *) "CREATE TEMPORARY TABLE desctable (col1 int4 not null, col2 numeric(4,2), col3 varchar(10) not null, col4 bigint not null)", SQL_NTS); | ||
CHECK_STMT_RESULT(rc, "SQLExecDirect failed while creating temp table", hstmt); | ||
|
||
/* Prepare a statement */ | ||
rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT * FROM desctable", SQL_NTS); | ||
CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); | ||
|
||
/* Execute */ | ||
rc = SQLExecute(hstmt); | ||
CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt); | ||
|
||
rc = SQLNumResultCols(hstmt, &colcount); | ||
CHECK_STMT_RESULT(rc, "SQLNumResultCols failed", hstmt); | ||
|
||
/* Get the descriptor handle */ | ||
rc = SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_ROW_DESC, &hDesc, 0, NULL); | ||
CHECK_STMT_RESULT(rc, "SQLGetStmtAttr failed", hstmt); | ||
|
||
for (int i = 1; i <= colcount; i++) | ||
{ | ||
rc = SQLGetDescRec(hDesc, i, name, nameLen, NULL, &type, &subType, &length, &precision, &scale, &nullable); | ||
if (!SQL_SUCCEEDED(rc)) | ||
{ | ||
print_diag("SQLGetDescRec failed", SQL_HANDLE_DESC, hDesc); | ||
exit(1); | ||
} | ||
|
||
printf("\n-- Column %d --\n", i); | ||
printf("SQL_DESC_NAME: %s\n", name); | ||
printf("SQL_DESC_TYPE: %d\n", type); | ||
printf("SQL_DESC_OCTET_LENGTH: %d\n", (int) length); | ||
printf("SQL_DESC_PRECISION: %d\n", precision); | ||
printf("SQL_DESC_SCALE: %d\n", scale); | ||
printf("SQL_DESC_NULLABLE: %d\n", nullable); | ||
} | ||
|
||
rc = SQLFreeStmt(hstmt, SQL_CLOSE); | ||
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); | ||
|
||
/* Clean up */ | ||
test_disconnect(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters