/* {{{ MADB_get_single_row */ my_bool MADB_get_single_row(MADB_Dbc *Connection, const char *StmtString, size_t Length, unsigned int NumCols, char **Buffers, size_t *Buffer_Lengths) { MYSQL_RES *result; MYSQL_ROW row; LOCK_MARIADB(Connection); if (mysql_real_query(Connection->mariadb, StmtString, Length) || mysql_field_count(Connection->mariadb) < NumCols) return 1; if ((result= mysql_store_result(Connection->mariadb)) && (row= mysql_fetch_row(result))) { unsigned int i; UNLOCK_MARIADB(Connection); for (i=0; i < NumCols; i++) strncpy_s(Buffers[i], Buffer_Lengths[i], row[i], Connection->mariadb->fields[i].max_length); mysql_free_result(result); return 0; } UNLOCK_MARIADB(Connection); return 1; }
MYSQL_RES *MADB_GetDefaultColumnValues(MADB_Stmt *Stmt, MYSQL_FIELD *fields) { DYNAMIC_STRING DynStr; unsigned int i; MYSQL_RES *result= NULL; init_dynamic_string(&DynStr, "SELECT COLUMN_NAME, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='", 512, 512); if (dynstr_append(&DynStr, fields[0].db) || dynstr_append(&DynStr, "' AND TABLE_NAME='") || dynstr_append(&DynStr, fields[0].org_table) || dynstr_append(&DynStr, "' AND COLUMN_NAME IN (")) goto error; for (i=0; i < mysql_stmt_field_count(Stmt->stmt); i++) { if (dynstr_append(&DynStr, i > 0 ? ",'" : "'") || dynstr_append(&DynStr, fields[i].org_name) || dynstr_append(&DynStr, "'")) goto error; } if (dynstr_append(&DynStr, ") AND COLUMN_DEFAULT IS NOT NULL")) goto error; LOCK_MARIADB(Stmt->Connection); if (mysql_query(Stmt->Connection->mariadb, DynStr.str)) goto error; result= mysql_store_result(Stmt->Connection->mariadb); error: UNLOCK_MARIADB(Stmt->Connection); dynstr_free(&DynStr); return result; }
MYSQL_RES *MADB_GetDefaultColumnValues(MADB_Stmt *Stmt, MYSQL_FIELD *fields) { MADB_DynString DynStr; unsigned int i; MYSQL_RES *result= NULL; MADB_InitDynamicString(&DynStr, "SELECT COLUMN_NAME, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='", 512, 512); if (MADB_DynstrAppend(&DynStr, fields[0].db) || MADB_DynstrAppend(&DynStr, "' AND TABLE_NAME='") || MADB_DynstrAppend(&DynStr, fields[0].org_table) || MADB_DynstrAppend(&DynStr, "' AND COLUMN_NAME IN (")) goto error; for (i=0; i < mysql_stmt_field_count(Stmt->stmt); i++) { MADB_DescRecord *Rec= MADB_DescGetInternalRecord(Stmt->Ard, i, MADB_DESC_READ); if (!Rec->inUse || MADB_ColumnIgnoredInAllRows(Stmt->Ard, Rec) == TRUE) { continue; } if (MADB_DynstrAppend(&DynStr, i > 0 ? ",'" : "'") || MADB_DynstrAppend(&DynStr, fields[i].org_name) || MADB_DynstrAppend(&DynStr, "'")) { goto error; } } if (MADB_DynstrAppend(&DynStr, ") AND COLUMN_DEFAULT IS NOT NULL")) goto error; LOCK_MARIADB(Stmt->Connection); if (mysql_query(Stmt->Connection->mariadb, DynStr.str)) goto error; result= mysql_store_result(Stmt->Connection->mariadb); error: UNLOCK_MARIADB(Stmt->Connection); MADB_DynstrFree(&DynStr); return result; }