Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sqlite/src/dttz.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ void register_date_functions(sqlite3 * db) {
}
}

void func_needs_vdbe(sqlite3_context *context, FuncDef *pFunc, Vdbe *pVdbe)
{
if (pFunc->xSFunc == currentTS || pFunc->xSFunc == nowFunc || pFunc->xSFunc == nextSequence)
context->pVdbe = pVdbe;
}

static int _convMem2ClientDatetime(Mem *pMem, void *out, int outlen,
int *outdtsz, int isstring)
{
Expand Down
1 change: 1 addition & 0 deletions sqlite/src/vdbeInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ int convMem2ClientDatetime(Mem *pMem, void *out);
int convMem2ClientDatetimeStr(Mem *pMem, void *out, int outlen, int *outdtsz);
int convDttz2ClientDatetime(const dttz_t *, const char *tzname, void *out, int sqltype);
const char *get_clnt_tz();
void func_needs_vdbe(sqlite3_context *context, FuncDef *pFunc, Vdbe *pVdbe);

int sqliteVdbeMemDecimalBasicArithmetics(Mem *a, Mem *b, int opcode, Mem * res, int flipped);

Expand Down
10 changes: 9 additions & 1 deletion sqlite/src/vdbemem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,15 @@ static int valueFromFunction(
ctx.pOut = pVal;
ctx.pFunc = pFunc;
#if defined(SQLITE_BUILDING_FOR_COMDB2)
ctx.pVdbe = db->pVdbe;
/* Certain comdb2 functions save info in pVdbe, and we need set the pVdbe
* pointer in the function context.
* Example: now() needs the the default precision to work.
* Sqlite json on the other hand expectgs db pVdbe pointer to be NULL
* as it is using it to store internal json info.
* Below function sets pVdbe in the function context only for comdb2
* variants that requires it.
*/
func_needs_vdbe(&ctx, pFunc, db->pVdbe);
#endif /* defined(SQLITE_BUILDING_FOR_COMDB2) */
pFunc->xSFunc(&ctx, nVal, apVal);
if( ctx.isError ){
Expand Down
1 change: 1 addition & 0 deletions tests/misstable_remsql.test/output_3.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(id=123, b1=x'59')
47 changes: 45 additions & 2 deletions tests/misstable_remsql.test/test_missing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ a_cdb2config=$4
a_dbdir=$5
a_testdir=$6

#TEST1 checking for missed table followed by good tables
echo "TEST1 checking for missed table followed by good tables"

output=run.out

REM_CDB2_OPTIONS="--cdb2cfg ${a_remcdb2config}"
Expand Down Expand Up @@ -51,7 +54,6 @@ cdb2sql ${SRC_CDB2_OPTIONS} --host $mach $a_dbname "select * from LOCAL_${a_remd
cdb2sql ${SRC_CDB2_OPTIONS} --tabs --host $mach $a_dbname "exec procedure sys.cmd.send(\"fdb info db\")" 2>&1 | cut -f 5- -d ' ' >> $output



#convert the table to actual dbname
sed "s/dorintdb/${a_remdbname}/g" output.log > output.log.actual

Expand All @@ -74,7 +76,8 @@ if [[ "$testcase_output" != "$expected_output" ]]; then
exit 1
fi

#TEST2 start by accessing a missing table, followed by good tables
#TEST2 following test one, again try to access a missing table, followed by good tables
echo "TEST2 following test one, again try to access a missing table, followed by good tables"

output=run.2.out

Expand Down Expand Up @@ -109,6 +112,7 @@ cdb2sql ${SRC_CDB2_OPTIONS} --host $mach $a_dbname "select dbname, tablename, in
sed "s/dorintdb/${a_remdbname}/g" output_2.log > output_2.log.actual

# validate results

testcase_output=$(cat $output)
expected_output=$(cat output_2.log.actual)
if [[ "$testcase_output" != "$expected_output" ]]; then
Expand All @@ -127,5 +131,44 @@ if [[ "$testcase_output" != "$expected_output" ]]; then
exit 1
fi

#TEST3 check that json_extract works - patch for function context
echo "TEST3 check that json_extract works - patch for function context"

output=run.3.out

cdb2sql ${REM_CDB2_OPTIONS} $a_remdbname default "analyze t" > $output 2>&1

echo cdb2sql ${SRC_CDB2_OPTIONS} $a_dbname default "select * from LOCAL_${a_remdbname}.t where json_extract( '{\"bb\":123}', '$.bb') = id"
cdb2sql ${SRC_CDB2_OPTIONS} $a_dbname default "select * from LOCAL_${a_remdbname}.t where json_extract( '{\"bb\":123}', '$.bb') = id" > $output 2>&1
cdb2sql ${SRC_CDB2_OPTIONS} $a_dbname default "select * from LOCAL_${a_remdbname}.t where json_extract( '{\"bb\":123}', '$.bb' ) = id"

if (( $? != 0 )) ; then
echo "Failure: select exit code $?"
exit 1
fi

#convert the table to actual dbname
sed "s/dorintdb/${a_remdbname}/g" output_3.log > output_3.log.actual

# validate results

testcase_output=$(cat $output)
expected_output=$(cat output_3.log.actual)
if [[ "$testcase_output" != "$expected_output" ]]; then

# print message
echo " ^^^^^^^^^^^^"
echo "The above testcase (${testcase}) has failed!!!"
echo " "
echo "Use 'diff <expected-output> <my-output>' to see why:"
echo "> diff ${PWD}/{output_2.log.actual,$output}"
echo " "
diff output_3.log.actual $output
echo " "

# quit
exit 1
fi


echo "Testcase passed."
Loading