/* * Tests INSERT RETURNING twice on the same statement */ #include #include #include "common.h" int main(int argc, char** argv) { SQLRETURN rc; HSTMT hstmt = SQL_NULL_HSTMT; SQLCHAR *sql; SQLINTEGER input = 0; SQLBIGINT xmin_out = 0; 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); } sql = "DROP TABLE IF EXISTS insertreturning_twice"; rc = SQLExecDirect(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed while dropping previous table", hstmt); sql = "CREATE TABLE insertreturning_twice (mycol int4)"; rc = SQLExecDirect(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLExecDirect failed while creating table", hstmt); sql = "INSERT INTO insertreturning_twice VALUES(?) RETURNING xmin::text::bigint"; rc = SQLPrepare(hstmt, sql, SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); rc = SQLBindCol(hstmt, 1, SQL_C_SBIGINT, &xmin_out, 0, NULL); CHECK_STMT_RESULT(rc, "SQLBindCol failed", hstmt); rc = SQLBindParam(hstmt, 1, SQL_C_SLONG, SQL_PARAM_INPUT, 0, 0, &input, NULL); CHECK_STMT_RESULT(rc, "SQLBindParam failed", hstmt); //Execute first insert ++input; rc = SQLExecute(hstmt); CHECK_STMT_RESULT(rc, "SQLExecute 1 failed", hstmt); rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch 1 failed", hstmt); if (xmin_out == 0) fprintf(stderr, "xmin 1 was not returned."); xmin_out = 0; while (SQL_SUCCEEDED(SQLMoreResults(hstmt))); //Execute second insert ++input; rc = SQLExecute(hstmt); CHECK_STMT_RESULT(rc, "SQLExecute 2 failed", hstmt); rc = SQLFetch(hstmt); CHECK_STMT_RESULT(rc, "SQLFetch 2 failed", hstmt); //Failure if (xmin_out == 0) fprintf(stderr, "xmin 2 was not returned."); test_disconnect(); }