ResultSet_T OracleConnection_executeQuery(T C, const char *sql, va_list ap) { OCIStmt* stmtp; va_list ap_copy; assert(C); C->rowsChanged = 0; va_copy(ap_copy, ap); StringBuffer_vset(C->sb, sql, ap_copy); va_end(ap_copy); StringBuffer_trim(C->sb); /* Build statement */ C->lastError = OCIHandleAlloc(C->env, (void **)&stmtp, OCI_HTYPE_STMT, 0, NULL); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) return NULL; C->lastError = OCIStmtPrepare(stmtp, C->err, StringBuffer_toString(C->sb), StringBuffer_length(C->sb), OCI_NTV_SYNTAX, OCI_DEFAULT); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) { OCIHandleFree(stmtp, OCI_HTYPE_STMT); return NULL; } /* Execute and create Result Set */ C->lastError = OCIStmtExecute(C->svc, stmtp, C->err, 0, 0, NULL, NULL, OCI_DEFAULT); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) { ub4 parmcnt = 0; OCIAttrGet(stmtp, OCI_HTYPE_STMT, &parmcnt, NULL, OCI_ATTR_PARSE_ERROR_OFFSET, C->err); DEBUG("Error occured in StmtExecute %d (%s), offset is %d\n", C->lastError, OracleConnection_getLastError(C), parmcnt); OCIHandleFree(stmtp, OCI_HTYPE_STMT); return NULL; } C->lastError = OCIAttrGet(stmtp, OCI_HTYPE_STMT, &C->rowsChanged, 0, OCI_ATTR_ROW_COUNT, C->err); if (C->lastError != OCI_SUCCESS && C->lastError != OCI_SUCCESS_WITH_INFO) DEBUG("OracleConnection_execute: Error in OCIAttrGet %d (%s)\n", C->lastError, OracleConnection_getLastError(C)); return ResultSet_new(OracleResultSet_new(stmtp, C->env, C->usr, C->err, C->svc, true, C->maxRows), (Rop_T)&oraclerops); }
ResultSet_T SQLitePreparedStatement_executeQuery(T P) { assert(P); if (P->lastError == SQLITE_OK) return ResultSet_new(SQLiteResultSet_new(P->stmt, P->maxRows, true), (Rop_T)&sqlite3rops); THROW(SQLException, "%s", sqlite3_errmsg(P->db)); return NULL; }
ResultSet_T SqlServerConnection_executeQuery(T C, const char *sql, va_list ap) { va_list ap_copy; const char *tail; SQLHSTMT hstmt; assert(C); StringBuffer_clear(C->sb); va_copy(ap_copy, ap); StringBuffer_vappend(C->sb, sql, ap_copy); va_end(ap_copy); C->lastError = SQLAllocStmt(C->db->hdbc,&hstmt); C->lastError = SQLPrepare(hstmt, StringBuffer_toString(C->sb), StringBuffer_length(C->sb)); if(!SQLSERVERSUCCESS(C->lastError)) { getSqlErr(C,hstmt); return NULL; } C->lastError = SQLExecute(hstmt); if(SQLSERVERSUCCESS(C->lastError)) return ResultSet_new(SqlServerResultSet_new(hstmt, C->maxRows, false), (Rop_T)&sqlserverrops); else { getSqlErr(C,hstmt); } return NULL; }
ResultSet_T OraclePreparedStatement_executeQuery(T P) { assert(P); P->rowsChanged = 0; P->lastError = OCIStmtExecute(P->svc, P->stmt, P->err, 0, 0, NULL, NULL, OCI_DEFAULT); if (P->lastError == OCI_SUCCESS || P->lastError == OCI_SUCCESS_WITH_INFO) return ResultSet_new(OracleResultSet_new(P->stmt, P->env, P->err, P->svc, false, P->maxRows), (Rop_T)&oraclerops); THROW(SQLException, "%s", OraclePreparedStatement_getLastError(P->lastError, P->err)); return NULL; }
ResultSet_T SqlServerPreparedStatement_executeQuery(T P) { assert(P); P->lastError = SQLExecute(P->stmt); if (SQLSERVERSUCCESS(P->lastError)) return ResultSet_new(SqlServerResultSet_new(P->stmt, P->maxRows, true), (Rop_T)&sqlserverrops); return NULL; }
ResultSet_T PostgresqlConnection_executeQuery(T C, const char *sql, va_list ap) { va_list ap_copy; assert(C); PQclear(C->res); va_copy(ap_copy, ap); StringBuffer_vset(C->sb, sql, ap_copy); va_end(ap_copy); C->res = PQexec(C->db, StringBuffer_toString(C->sb)); C->lastError = PQresultStatus(C->res); if (C->lastError == PGRES_TUPLES_OK) return ResultSet_new(PostgresqlResultSet_new(C->res, C->maxRows), (Rop_T)&postgresqlrops); return NULL; }
ResultSet_T MysqlPreparedStatement_executeQuery(T P) { assert(P); if (P->parameterCount > 0) if ((P->lastError = mysql_stmt_bind_param(P->stmt, P->bind))) THROW(SQLException, "%s", mysql_stmt_error(P->stmt)); #if MYSQL_VERSION_ID >= 50002 unsigned long cursor = CURSOR_TYPE_READ_ONLY; mysql_stmt_attr_set(P->stmt, STMT_ATTR_CURSOR_TYPE, &cursor); #endif if ((P->lastError = mysql_stmt_execute(P->stmt))) THROW(SQLException, "%s", mysql_stmt_error(P->stmt)); if (P->lastError == MYSQL_OK) return ResultSet_new(MysqlResultSet_new(P->stmt, P->maxRows, true), (Rop_T)&mysqlrops); THROW(SQLException, "%s", mysql_stmt_error(P->stmt)); return NULL; }
ResultSet_T MysqlConnection_executeQuery(T C, const char *sql, va_list ap) { va_list ap_copy; MYSQL_STMT *stmt = NULL; assert(C); StringBuffer_clear(C->sb); va_copy(ap_copy, ap); StringBuffer_vappend(C->sb, sql, ap_copy); va_end(ap_copy); if (prepare(C, StringBuffer_toString(C->sb), StringBuffer_length(C->sb), &stmt)) { #if MYSQL_VERSION_ID >= 50002 unsigned long cursor = CURSOR_TYPE_READ_ONLY; mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor); #endif if ((C->lastError = mysql_stmt_execute(stmt))) { StringBuffer_clear(C->sb); StringBuffer_append(C->sb, "%s", mysql_stmt_error(stmt)); mysql_stmt_close(stmt); } else return ResultSet_new(MysqlResultSet_new(stmt, C->maxRows, false), (Rop_T)&mysqlrops); } return NULL; }