Skip to content

Commit

Permalink
Change how to request non null type for typessql
Browse files Browse the repository at this point in the history
Signed-off-by: Salil Chandra <schandra107@bloomberg.net>
  • Loading branch information
chands10 committed Oct 6, 2023
1 parent 4aeb750 commit fbac733
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion db/dohsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ static int inner_columns(struct sqlclntstate *clnt, sqlite3_stmt *stmt)
conn->ncols = ncols;

for (i = 0; i < ncols; i++) {
conn->cols[i].type = get_sqlite3_column_type(clnt, stmt, i, 0);
conn->cols[i].type = get_sqlite3_column_type(clnt, stmt, i, 0, 0);
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion db/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ int sqlite3_is_success(int);
int sqlite3_is_prepare_only(struct sqlclntstate *);
int sqlite3_maybe_step(struct sqlclntstate *, sqlite3_stmt *);
int get_sqlite3_column_type(struct sqlclntstate *clnt, sqlite3_stmt *stmt,
int col, int skip_decltype);
int col, int skip_decltype, int non_null_type);
int is_column_type_null(struct sqlclntstate *clnt, sqlite3_stmt *stmt, int col);

int column_type(struct sqlclntstate *, sqlite3_stmt *, int);
Expand Down
11 changes: 7 additions & 4 deletions db/sqlinterfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,15 +984,18 @@ int validate_columns(struct sqlclntstate *clnt, sqlite3_stmt *stmt)
}

int get_sqlite3_column_type(struct sqlclntstate *clnt, sqlite3_stmt *stmt,
int col, int skip_decltype)
int col, int skip_decltype, int non_null_type)
{
int type = SQLITE_NULL;
int ncols = column_count(clnt, stmt);

if (sqlite3_can_get_column_type_and_data(clnt, stmt)) {
type = column_type(clnt, stmt, col);
int colNum = col;
if (clnt->typessql_state && non_null_type)
colNum += ncols;
type = column_type(clnt, stmt, colNum);
if (type == SQLITE_NULL && !skip_decltype) {
type = typestr_to_type(sqlite3_column_decltype(stmt, col >= ncols ? col - ncols : col));
type = typestr_to_type(sqlite3_column_decltype(stmt, col));
}
if (type == SQLITE_DECIMAL) {
type = SQLITE_TEXT;
Expand All @@ -1004,7 +1007,7 @@ int get_sqlite3_column_type(struct sqlclntstate *clnt, sqlite3_stmt *stmt,
int is_column_type_null(struct sqlclntstate *clnt, sqlite3_stmt *stmt, int col)
{
if (!clnt->fdb_push) {
return get_sqlite3_column_type(clnt, stmt, col, 1) == SQLITE_NULL ||
return get_sqlite3_column_type(clnt, stmt, col, 1, 0) == SQLITE_NULL ||
column_type(clnt, stmt, col) == SQLITE_NULL;
}

Expand Down
11 changes: 5 additions & 6 deletions plugins/newsql/newsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,18 @@ static int newsql_send_hdr(struct sqlclntstate *clnt, int h, int s)
}

static int get_col_type(struct sqlclntstate *clnt, sqlite3_stmt *stmt, int col,
int check_protocol_version)
int check_protocol_version, int non_null_type)
{
struct newsql_appdata *appdata = clnt->appdata;
CDB2SQLQUERY *sql_query = appdata->sqlquery;
int type = -1;
int ncols = column_count(clnt, stmt);
if (sql_query->n_types) {
type = sql_query->types[col >= ncols ? col - ncols : col];
type = sql_query->types[col];
if (type == SQLITE_DECIMAL) {
type = SQLITE_TEXT;
}
} else if (stmt) {
type = get_sqlite3_column_type(clnt, stmt, col, 0);
type = get_sqlite3_column_type(clnt, stmt, col, 0, non_null_type);
if ((check_protocol_version == 1 && appdata->protocol_version == 1 /* fastsql */) ||
type == SQLITE_NULL) {
type = typestr_to_type(sqlite3_column_decltype(stmt, col));
Expand Down Expand Up @@ -390,7 +389,7 @@ static int newsql_columns(struct sqlclntstate *clnt, sqlite3_stmt *stmt)
cols[i].value.data = (uint8_t *)name;
cols[i].value.len = len;
cols[i].has_type = 1;
cols[i].type = appdata->col_info.type[i] = get_col_type(clnt, stmt,clnt->typessql_state ? i + ncols : i, 1);
cols[i].type = appdata->col_info.type[i] = get_col_type(clnt, stmt, i, 1, clnt->typessql_state != NULL);
}
CDB2SQLRESPONSE resp = CDB2__SQLRESPONSE__INIT;
resp.response_type = RESPONSE_TYPE__COLUMN_NAMES;
Expand Down Expand Up @@ -447,7 +446,7 @@ static int newsql_columns_lua(struct sqlclntstate *clnt,
cols[i].value.len = len;
cols[i].has_type = 1;
cols[i].type = appdata->col_info.type[i] =
sp_column_type(arg, i, n_types, get_col_type(clnt, stmt, i, 0));
sp_column_type(arg, i, n_types, get_col_type(clnt, stmt, i, 0, 0));
}
clnt->osql.sent_column_data = 1;
CDB2SQLRESPONSE resp = CDB2__SQLRESPONSE__INIT;
Expand Down

0 comments on commit fbac733

Please sign in to comment.