int main(int argc, char *argv[]) { attachsql_connect_t *con= NULL; attachsql_error_st *error= NULL; const char *query= "SELECT * FROM t1 WHERE name='fred'"; attachsql_return_t ret= ATTACHSQL_RETURN_NONE; attachsql_query_row_st *row; uint16_t columns, current_column; con= attachsql_connect_create("localhost", 3306, "test", "test", "testdb", NULL); error= attachsql_query(con, strlen(query), query, 0, NULL); while ((ret != ATTACHSQL_RETURN_EOF) && (error == NULL)) { ret= attachsql_connect_poll(con, &error); if (ret != ATTACHSQL_RETURN_ROW_READY) { continue; } row= attachsql_query_row_get(con, &error); columns= attachsql_query_column_count(con); for (current_column= 0; current_column < columns; current_column++) { printf("%.*s ", (int)row[current_column].length, row[current_column].data); } printf("\n"); attachsql_query_row_next(con); } if (error != NULL) { printf("Error occurred: %s", error->msg); } attachsql_query_close(con); attachsql_connect_destroy(con); }
void _attachsql_QueryObject_dealloc(_attachsql_QueryObject *self) { PyObject_GC_UnTrack(self); if (!self->pycon->in_pool) { attachsql_query_close(self->pycon->conn); } self->pycon->query= NULL; Py_XDECREF(self->pycon); self->ob_type->tp_free(self); }
int attachsql_drv_free_results(db_result_set_t *rs) { if (rs->connection->ptr != NULL) { DEBUG("attachsql_query_close(%p)", rs->connection->ptr); attachsql_query_close(rs->connection->ptr); return 0; } return 1; }
int main(void) { attachsql_connect_t *con= NULL; attachsql_error_t *error= NULL; const char *query= "SELECT * FROM t1 WHERE name = ? AND age > ?"; attachsql_return_t ret= ATTACHSQL_RETURN_NONE; attachsql_query_row_st *row; uint16_t columns, current_column; attachsql_query_parameter_st param[2]; con= attachsql_connect_create("localhost", 3306, "test", "test", "testdb", NULL); const char *name= "fred"; uint32_t age= 30; param[0].type= ATTACHSQL_ESCAPE_TYPE_CHAR; param[0].data= (char*)name; param[0].length= strlen(name); param[1].type= ATTACHSQL_ESCAPE_TYPE_INT; param[1].data= &age; param[1].is_unsigned= true; attachsql_query(con, strlen(query), query, 2, param, &error); while ((ret != ATTACHSQL_RETURN_EOF) && (error == NULL)) { ret= attachsql_connect_poll(con, &error); if (ret != ATTACHSQL_RETURN_ROW_READY) { continue; } row= attachsql_query_row_get(con, &error); columns= attachsql_query_column_count(con); for (current_column= 0; current_column < columns; current_column++) { printf("%.*s ", (int)row[current_column].length, row[current_column].data); } printf("\n"); attachsql_query_row_next(con); } if (error != NULL) { printf("Error occurred: %s", attachsql_error_message(error)); attachsql_error_free(error); } attachsql_query_close(con); attachsql_connect_destroy(con); }
int attachsql_drv_query(db_conn_t *sb_conn, const char *query, db_result_set_t *rs) { (void) rs; attachsql_connect_t *con = sb_conn->ptr; unsigned int rc; attachsql_error_t *error= NULL; attachsql_return_t aret= ATTACHSQL_RETURN_NONE; /* Close any previous query */ attachsql_query_close(con); DEBUG("attachsql_query(%p, \"%s\", %u)", con, query, strlen(query)); attachsql_query(con, strlen(query), query, 0, NULL, &error); while((aret != ATTACHSQL_RETURN_EOF) && (aret != ATTACHSQL_RETURN_ROW_READY)) { aret= attachsql_connect_poll(con, &error); if (error) { rc= attachsql_error_code(error); if (rc == 1213 || rc == 1205 || rc == 1020) { attachsql_error_free(error); return SB_DB_ERROR_DEADLOCK; } log_text(LOG_ALERT, "libAttachSQL Query Failed: %u:%s", attachsql_error_code(error), attachsql_error_message(error)); attachsql_error_free(error); return SB_DB_ERROR_FAILED; } } //rs->connection->ptr= con; DEBUG("attachsql_query \"%s\" returned %d", query, aret); return SB_DB_ERROR_NONE; }