Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Douglas <[email protected]>

Add to refactor

Signed-off-by: Morgan Douglas <[email protected]>

Add to refactor

Signed-off-by: Morgan Douglas <[email protected]>

Add to refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

WIP completerbuf->std::string

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>

Tweak refactor

Signed-off-by: Morgan Douglas <[email protected]>
  • Loading branch information
morgando committed Dec 27, 2024
1 parent 50f7533 commit f423e7f
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 401 deletions.
26 changes: 13 additions & 13 deletions cdb2api/cdb2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,8 @@ static int cdb2_convert_error_code(int rc)
return CDB2ERR_DUPLICATE;
case CDB2__ERROR_CODE__PREPARE_ERROR_OLD:
return CDB2ERR_PREPARE_ERROR;
case CDB2__ERROR_CODE__INCOMPLETE:
return CDB2ERR_INCOMPLETE;
default:
return rc;
}
Expand Down Expand Up @@ -7279,20 +7281,18 @@ char *cdb2_string_escape(cdb2_hndl_tp *hndl, const char *src)
}

int cdb2_get_property(cdb2_hndl_tp *hndl, const char *key, char **value) {
if (hndl == NULL)
if (hndl == NULL) {
return CDB2ERR_NOSTATEMENT;
} else if (strcmp(key, "sql:tail") != 0) {
return CDB2ERR_UNKNOWN_PROPERTY;
} else if (hndl->firstresponse == NULL) {
return CDB2ERR_NOSTATEMENT;
*value = NULL;
if (strcmp(key, "sql:tail") == 0) {
if (hndl->firstresponse == NULL)
return CDB2ERR_NOSTATEMENT;
if (!hndl->firstresponse->has_sql_tail_offset) {
return CDB2ERR_OLD_SERVER;
}
char *str = malloc(20);
sprintf(str, "%d", hndl->firstresponse->sql_tail_offset);
*value = str;
} else if (!hndl->firstresponse->has_sql_tail_offset) {
return CDB2ERR_OLD_SERVER;
} else {
*value = malloc(20);
if (!value) { return ENOMEM; }
sprintf(*value, "%d", hndl->firstresponse->sql_tail_offset);
return 0;
}
else
return CDB2ERR_UNKNOWN_PROPERTY;
}
4 changes: 3 additions & 1 deletion cdb2api/cdb2api.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ enum cdb2_errors {
CDB2ERR_BADSTATE = -8,
CDB2ERR_ASYNCERR = -9,
CDB2_OK_ASYNC = -10,
CDB2ERR_INCOMPLETE = -11,
CDB2ERR_INVALID_ID = -12,
CDB2ERR_RECORD_OUT_OF_RANGE = -13,

Expand Down Expand Up @@ -110,6 +109,7 @@ enum cdb2_errors {
CDB2ERR_CHECK_CONSTRAINT = 403,
CDB2ERR_DIST_ABORT = 410,
CDB2ERR_QUERY_REJECTED = 451,
CDB2ERR_INCOMPLETE = 452,

CDB2ERR_UNKNOWN = 300

Expand Down Expand Up @@ -272,6 +272,8 @@ char *cdb2_string_escape(cdb2_hndl_tp *hndl, const char *str);
int cdb2_send_2pc(cdb2_hndl_tp *hndl, char *dbname, char *pname, char *ptier, char *source, unsigned int op,
char *dist_txnid, int rcode, int outrc, char *errmsg, int async);

// on success, `*value` points to dynamically allocated memory
// that must be freed by the caller.
int cdb2_get_property(cdb2_hndl_tp *hndl, const char *key, char **value);

typedef enum cdb2_event_ctrl {
Expand Down
1 change: 1 addition & 0 deletions db/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ enum {
XRESPONSE(RESPONSE_ERROR_PREPARE) \
XRESPONSE(RESPONSE_ERROR_PREPARE_RETRY) \
XRESPONSE(RESPONSE_ERROR_REJECT) \
XRESPONSE(RESPONSE_ERROR_INCOMPLETE) \
XRESPONSE(RESPONSE_REDIRECT_FOREIGN) \
XRESPONSE(RESPONSE_FLUSH) \
XRESPONSE(RESPONSE_HEARTBEAT) \
Expand Down
15 changes: 14 additions & 1 deletion db/sqlinterfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -2911,7 +2911,11 @@ static void _prepare_error(struct sqlthdstate *thd,
}
reqlog_logf(thd->logger, REQL_TRACE, "sqlite3_prepare failed %d: %s\n", rc,
errstr);
errstat_set_rcstrf(err, ERR_PREPARE, "%s", errstr);

const int err_code = rc == SQLITE_MISSING_SEMI
? RESPONSE_ERROR_INCOMPLETE : ERR_PREPARE;

errstat_set_rcstrf(err, err_code, "%s", errstr);
if (clnt->saved_errstr) {
free(clnt->saved_errstr);
}
Expand Down Expand Up @@ -3137,6 +3141,10 @@ static int get_prepared_stmt_int(struct sqlthdstate *thd,
if (prepareOnly || sqlite3_is_prepare_only(clnt))
sqlPrepFlags |= SQLITE_PREPARE_ONLY;

if (clnt->multiline) {
sqlPrepFlags |= SQLITE_PREPARE_REQUIRE_SEMI;
}

if (!gbl_allow_pragma)
flags |= PREPARE_DENY_PRAGMA;

Expand Down Expand Up @@ -4048,6 +4056,8 @@ int handle_sqlite_requests(struct sqlthdstate *thd, struct sqlclntstate *clnt)
if (irc == ERR_PREPARE) {
write_response(clnt, RESPONSE_ERROR_PREPARE, err.errstr, 0);
handle_sqlite_error(thd, clnt, &rec, rc);
} else if (irc == RESPONSE_ERROR_INCOMPLETE) {
write_response(clnt, RESPONSE_ERROR_INCOMPLETE, err.errstr, 0);
} else if (irc == ERR_PREPARE_RETRY) {
write_response(clnt, RESPONSE_ERROR_PREPARE_RETRY, err.errstr, 0);
rc = 0;
Expand Down Expand Up @@ -6347,6 +6357,7 @@ int sql_check_errors(struct sqlclntstate *clnt, sqlite3 *sqldb,
case SQLITE_NO_TEMPTABLES:
case SQLITE_NO_TABLESCANS:
case SQLITE_ANALYZE_ALREADY_RUNNING:
case SQLITE_PREPARE_REQUIRE_SEMI:
*errstr = sqlite3_errmsg(sqldb);
break;

Expand Down Expand Up @@ -6520,6 +6531,8 @@ int sqlserver2sqlclient_error(int rc)
return CDB2ERR_PREPARE_ERROR;
case SQLITE_ANALYZE_ALREADY_RUNNING:
return CDB2ERR_ANALYZE_ALREADY_RUNNING;
case SQLITE_MISSING_SEMI:
return RESPONSE_ERROR_INCOMPLETE;
default:
return CDB2ERR_UNKNOWN;
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/newsql/newsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ static int newsql_write_response(struct sqlclntstate *c, int t, void *a, int i)
case RESPONSE_ERROR_BAD_STATE: return newsql_error(c, a, CDB2__ERROR_CODE__BADSTATE);
case RESPONSE_ERROR_PREPARE: return newsql_error(c, a, CDB2__ERROR_CODE__PREPARE_ERROR);
case RESPONSE_ERROR_REJECT: return newsql_error(c, a, CDB2__ERROR_CODE__REJECTED);
case RESPONSE_ERROR_INCOMPLETE: return newsql_error(c, a, CDB2__ERROR_CODE__INCOMPLETE);
case RESPONSE_REDIRECT_FOREIGN: return newsql_redirect_foreign(c, a, i);
case RESPONSE_FLUSH: return c->plugin.flush(c);
case RESPONSE_HEARTBEAT: return newsql_heartbeat(c);
Expand Down Expand Up @@ -2053,6 +2054,7 @@ int process_set_commands(struct sqlclntstate *clnt, CDB2SQLQUERY *sql_query)
clnt->return_long_column_names = 0;
} else {
clnt->return_long_column_names = 1;
}
} else if (strncasecmp(sqlstr, "multiline", 9) == 0) {
sqlstr += 10;
sqlstr = skipws(sqlstr);
Expand Down
Loading

0 comments on commit f423e7f

Please sign in to comment.