Message-ID: From: "davecramer (@davecramer)" To: "postgresql-interfaces/psqlodbc" Date: Fri, 20 Sep 2024 15:17:12 +0000 Subject: Re: [postgresql-interfaces/psqlodbc] issue #43: syntax error at or near "ROWS" In-Reply-To: References: List-Id: X-GitHub-Author-Login: davecramer X-GitHub-Comment-Id: 2363970238 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 43 X-GitHub-Repo: postgresql-interfaces/psqlodbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/postgresql-interfaces/psqlodbc/issues/43#issuecomment-2363970238 Content-Type: text/plain; charset=utf-8 So I wrote some code and test this. Slightly different table works fine. ``` create table serversession("Id" serial , "Begin" int4, "End" int4, logfile text); ``` ``` rc = SQLExecDirect(hstmt, (SQLCHAR *) "SET intervalstyle=postgres_verbose", SQL_NTS); /* Prepare a statement */ rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT \"Id\",\"Begin\",\"End\",\"Logfile\" FROM ServerSession ORDER BY \"Begin\" ASC OFFSET ? ROWS FETCH FIRST ? ROW ONLY", SQL_NTS); CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt); /* bind param */ longparam1 = 0; cbParam1 = sizeof(longparam1); rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, /* value type */ SQL_INTEGER, /* param type */ 0, /* column size (ignored for SQL_INTEGER) */ 0, /* dec digits */ &longparam1, /* param value ptr */ sizeof(longparam1), /* buffer len (ignored for SQL_INTEGER) */ &cbParam1 /* StrLen_or_IndPtr (ignored for SQL_INTEGER) */); CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt); /* bind param */ longparam2 = 3; cbParam2 = sizeof(longparam2); rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, /* value type */ SQL_INTEGER, /* param type */ 0, /* column size (ignored for SQL_INTEGER) */ 0, /* dec digits */ &longparam2, /* param value ptr */ sizeof(longparam2), /* buffer len (ignored for SQL_INTEGER) */ &cbParam2 /* StrLen_or_IndPtr (ignored for SQL_INTEGER) */); CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt); /* Test SQLNumResultCols, called before SQLExecute() */ rc = SQLNumResultCols(hstmt, &colcount); CHECK_STMT_RESULT(rc, "SQLNumResultCols failed", hstmt); printf("# of result cols: %d\n", colcount); /* Execute */ rc = SQLExecute(hstmt); CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt); /* Fetch result */ print_result(hstmt); rc = SQLFreeStmt(hstmt, SQL_CLOSE); CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt); /* Clean up */ test_disconnect(); ```