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 OracleConnection_executeQuery(T C, const char *sql, va_list ap) { OCIStmt* stmtp; va_list ap_copy; assert(C); C->rowsChanged = 0; StringBuffer_clear(C->sb); va_copy(ap_copy, ap); StringBuffer_vappend(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->err, C->svc, true, C->maxRows), (Rop_T)&oraclerops); }
int MysqlConnection_execute(T C, const char *sql, va_list ap) { va_list ap_copy; assert(C); StringBuffer_clear(C->sb); va_copy(ap_copy, ap); StringBuffer_vappend(C->sb, sql, ap_copy); va_end(ap_copy); C->lastError = mysql_real_query(C->db, StringBuffer_toString(C->sb), StringBuffer_length(C->sb)); return (C->lastError == MYSQL_OK); }
int SqlServerConnection_execute(T C, const char *sql, va_list ap) { va_list ap_copy; assert(C); StringBuffer_clear(C->sb); va_copy(ap_copy, ap); StringBuffer_vappend(C->sb, sql, ap_copy); va_end(ap_copy); executeSQL(C, StringBuffer_toString(C->sb)); return (SQLSERVERSUCCESS(C->lastError)); }
PreparedStatement_T MysqlConnection_prepareStatement(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)) return PreparedStatement_new(MysqlPreparedStatement_new(stmt, C->maxRows), (Pop_T)&mysqlpops); return NULL; }
PreparedStatement_T OracleConnection_prepareStatement(T C, const char *sql, va_list ap) { OCIStmt *stmtp; va_list ap_copy; assert(C); StringBuffer_clear(C->sb); va_copy(ap_copy, ap); StringBuffer_vappend(C->sb, sql, ap_copy); va_end(ap_copy); StringBuffer_trim(C->sb); StringBuffer_prepare4oracle(C->sb); /* Build statement */ C->lastError = OCIHandleAlloc(C->env, (void **)&stmtp, OCI_HTYPE_STMT, 0, 0); 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; } return PreparedStatement_new(OraclePreparedStatement_new(stmtp, C->env, C->err, C->svc, C->maxRows), (Pop_T)&oraclepops); }
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; }
PreparedStatement_T SqlServerConnection_prepareStatement(T C, const char *sql, va_list ap) { va_list ap_copy; const char *tail; HSTMT 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),strlen(StringBuffer_toString(C->sb))); //The third argument with an array of the same size , but not the same database column if (SQLSERVERSUCCESS(C->lastError)) { int paramCount = 0; return PreparedStatement_new(SqlServerPreparedStatement_new(C->db, hstmt, C->maxRows), (Pop_T)&sqlserverpops, paramCount); } else { getSqlErr(C,hstmt); } return NULL; }
static void append(StringBuffer_T B, const char *s, ...) { va_list ap; va_start(ap, s); StringBuffer_vappend(B, s, ap); va_end(ap); }