psqlodbc.git / summary / log / commit / refs

commit    f8cf73d2ff3db9fc4cc022ed7f1de16ccca8a0e5
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Tue Dec 02 11:15:57 2014 +0000

    Add test cases for:
    
    * getting a bookmark with SQLBindCol,
    * unbinding columns with SQLBindCol and SQLFreeStmt(SQL_UNBIND), and
    * the procedure call "{ CALL ... }", and date, time, and timestamp escape
      syntaxes.


test/expected/bindcol.out | 13 ++++++++++--- test/expected/bookmark.out | 7 +++++++ test/expected/odbc-escapes.out | 23 +++++++++++++++++++++++ test/src/bindcol-test.c | 37 +++++++++++++++++++++++++++++++------ test/src/bookmark-test.c | 24 ++++++++++++++++++++++++ test/src/odbc-escapes-test.c | 26 ++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 9 deletions(-) diff --git a/test/expected/bindcol.out b/test/expected/bindcol.out index 8a6b9b07..9c152543 100644 --- a/test/expected/bindcol.out +++ b/test/expected/bindcol.out @@ -1,7 +1,14 @@ \! "./src/bindcol-test" connected Result set: -1 foo -2 bar -3 foobar +1 foo1 +2 foo2 +3 foo3 +4 foo3 +5 foo3 +6 foo6 +7 foo7 +7 foo7 +7 foo7 +7 foo10 disconnecting diff --git a/test/expected/bookmark.out b/test/expected/bookmark.out index 061d348c..7cd2a91a 100644 --- a/test/expected/bookmark.out +++ b/test/expected/bookmark.out @@ -17,4 +17,11 @@ Testing SQL_FETCH_BOOKMARK, middle (10)... fetched: foo111 Testing SQL_FETCH_BOOKMARK, middle (-10)... fetched: foo91 +Getting bookmark with SQLBindCol... +fetched: foo100 +Unbinding boomark column... +Moving +100... +fetched: foo200 +Goind back to bookmark acquired with SQLBindCol... +fetched: foo100 disconnecting diff --git a/test/expected/odbc-escapes.out b/test/expected/odbc-escapes.out index 600ef057..c32a0241 100644 --- a/test/expected/odbc-escapes.out +++ b/test/expected/odbc-escapes.out @@ -16,4 +16,27 @@ Result set: Query: SELECT 'x' || {fn SPACE(10) } || 'x' Result set: x x + +Query: { call length(?) } +Param 1: foobar +Result set: +6 + +Query: { call right(?, ?) } +Param 1: foobar +Param 2: 3 +Result set: +bar + +Query: SELECT {d '2014-12-21' } + '1 day'::interval +Result set: +2014-12-22 00:00:00 + +Query: SELECT {t '20:30:40' } + '1 hour 1 minute 1 second'::interval +Result set: +21:31:41 + +Query: SELECT {ts '2014-12-21 20:30:40' } + '1 day 1 hour 1 minute 1 second'::interval +Result set: +2014-12-22 21:31:41 disconnecting diff --git a/test/src/bindcol-test.c b/test/src/bindcol-test.c index 4d2dd0c9..62326ed9 100644 --- a/test/src/bindcol-test.c +++ b/test/src/bindcol-test.c @@ -6,8 +6,8 @@ int main(int argc, char **argv) { - int rc; - HSTMT hstmt = SQL_NULL_HSTMT; + int rc; + HSTMT hstmt = SQL_NULL_HSTMT; /* * NOTE: in the psqlodbc, we assume that SQL_C_LONG actually means a * variable of type SQLINTEGER. They are not the same on platforms where @@ -16,10 +16,11 @@ int main(int argc, char **argv) * (on little-endian systems, you won't notice the difference if you reset * the high bits to zero before calling SQLBindCol.) */ - SQLINTEGER longvalue; + SQLINTEGER longvalue; SQLLEN indLongvalue; - char charvalue[100]; - SQLLEN indCharvalue; + char charvalue[100]; + SQLLEN indCharvalue; + int rowno; test_connect(); @@ -36,10 +37,12 @@ int main(int argc, char **argv) rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, &charvalue, sizeof(charvalue), &indCharvalue); CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt); - rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT * FROM testtab1 ORDER BY id", SQL_NTS); + rc = SQLExecDirect(hstmt, (SQLCHAR *) + "SELECT id, 'foo' || id FROM generate_series(1, 10) id", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt); printf("Result set:\n"); + rowno = 0; while(1) { rc = SQLFetch(hstmt); @@ -54,6 +57,28 @@ int main(int argc, char **argv) print_diag("SQLFetch failed", SQL_HANDLE_STMT, hstmt); exit(1); } + + /* + * At row 3, unbind the text field. At row 5, bind it again. + * At row 7, unbind both columns with SQLFreeStmt(SQL_UNBIND). + * At row 9, bind text field again. + */ + rowno++; + if (rowno == 3) + { + rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, NULL, 0, NULL); + CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt); + } + if (rowno == 7) + { + rc = SQLFreeStmt(hstmt, SQL_UNBIND); + CHECK_STMT_RESULT(rc, "SQLFreeStmt(SQL_UNBIND) failed", hstmt); + } + if (rowno == 5 || rowno == 9) + { + rc = SQLBindCol(hstmt, 2, SQL_C_CHAR, &charvalue, sizeof(charvalue), &indCharvalue); + CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt); + } } rc = SQLFreeStmt(hstmt, SQL_CLOSE); diff --git a/test/src/bookmark-test.c b/test/src/bookmark-test.c index 1f554376..ccdfa5e8 100644 --- a/test/src/bookmark-test.c +++ b/test/src/bookmark-test.c @@ -103,6 +103,30 @@ testBookmarks(HSTMT hstmt) rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, -10); printFetchResult(hstmt, rc); + /*** Test getting a bookmark with SQLBindCol */ + printf("Getting bookmark with SQLBindCol...\n"); + rc = SQLBindCol(hstmt, 0, SQL_C_VARBOOKMARK, book_middle, sizeof(book_middle), &book_middle_ind); + CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt); + + rc = SQLFetchScroll(hstmt, SQL_FETCH_ABSOLUTE, 100); + printFetchResult(hstmt, rc); + + printf("Unbinding boomark column...\n"); + rc = SQLBindCol(hstmt, 0, SQL_C_VARBOOKMARK, NULL, 0, NULL); + CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt); + + printf("Moving +100...\n"); + rc = SQLFetchScroll(hstmt, SQL_FETCH_RELATIVE, 100); + printFetchResult(hstmt, rc); + + printf("Goind back to bookmark acquired with SQLBindCol...\n"); + rc = SQLSetStmtAttr(hstmt, SQL_ATTR_FETCH_BOOKMARK_PTR, + (SQLPOINTER) book_middle, SQL_IS_POINTER); + CHECK_STMT_RESULT(rc, "SQLSetStmtAttr failed", hstmt); + + rc = SQLFetchScroll(hstmt, SQL_FETCH_BOOKMARK, 0); + printFetchResult(hstmt, rc); + rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); } diff --git a/test/src/odbc-escapes-test.c b/test/src/odbc-escapes-test.c index 75a00c6b..0e479e4a 100644 --- a/test/src/odbc-escapes-test.c +++ b/test/src/odbc-escapes-test.c @@ -82,6 +82,32 @@ int main(int argc, char **argv) prepareQuery(hstmt, "SELECT 'x' || {fn SPACE(10) } || 'x'"); executeQuery(hstmt); + /**** CALL escapes ****/ + + prepareQuery(hstmt, "{ call length(?) }"); + bindParamString(hstmt, 1, "foobar"); + executeQuery(hstmt); + + prepareQuery(hstmt, "{ call right(?, ?) }"); + bindParamString(hstmt, 1, "foobar"); + bindParamString(hstmt, 2, "3"); + executeQuery(hstmt); + + /* TODO: This doesn't currently work. + prepareQuery(hstmt, "{ ? = call concat(?, ?) }"); + */ + + /**** Date, Time, and Timestamp literals ****/ + + prepareQuery(hstmt, "SELECT {d '2014-12-21' } + '1 day'::interval"); + executeQuery(hstmt); + + prepareQuery(hstmt, "SELECT {t '20:30:40' } + '1 hour 1 minute 1 second'::interval"); + executeQuery(hstmt); + + prepareQuery(hstmt, "SELECT {ts '2014-12-21 20:30:40' } + '1 day 1 hour 1 minute 1 second'::interval"); + executeQuery(hstmt); + /* Clean up */ test_disconnect(); [parent: cc6f739ed3c5]