Skip to content

Commit

Permalink
Check comments about possible NaN processing
Browse files Browse the repository at this point in the history
  • Loading branch information
mkgrgis committed May 13, 2024
1 parent c293164 commit cbde7e8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
9 changes: 5 additions & 4 deletions deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2691,10 +2691,11 @@ sqlite_deparse_const(Const *node, deparse_expr_cxt *context, int showtype)
else if (strcasecmp(extval, "NaN") == 0)
{
/* https://stackoverflow.com/questions/20619957
* https://github.com/sqlite/sqlite/blob/6db0b11e078f4b651f0cf00f845f3d77700c1a3a/src/vdbemem.c#L973
* appendStringInfo(buf, "NULL");
*/
appendStringInfo(buf, "'NaN'");
* https://github.com/sqlite/sqlite/blob/6db0b11e078f4b651f0cf00f845f3d77700c1a3a/src/vdbemem.c#L973
* TODO: check possible alternative
* appendStringInfo(buf, "NULL");
*/
appendStringInfo(buf, "'NaN'");
}
else
{
Expand Down
36 changes: 20 additions & 16 deletions sqlite_data_norm.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,25 @@
*-------------------------------------------------------------------------
*/

#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

#include "sqlite3.h"
#include "postgres.h"
#include "sqlite_fdw.h"
#include "utils/uuid.h"

static void error_helper(sqlite3* db, int rc);

#if !defined(SQLITE_ASCII) && !defined(SQLITE_EBCDIC)
#define SQLITE_ASCII 1
#endif

/*
* This SQLite extension implements functions that handling RFC-4122 UUIDs
* This UUID SQLite extension as a group of UUID C functions
* implements functions that handling RFC-4122 UUIDs
* Three SQL functions are implemented:
*
* sqlite_fdw_uuid_str(X) - convert a UUID X into a well-formed UUID string
Expand Down Expand Up @@ -63,21 +80,6 @@
* If the X input string has too few or too many digits or contains
* stray characters other than {, }, or -, then NULL is returned.
*/
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

#include "sqlite3.h"
#include "postgres.h"
#include "sqlite_fdw.h"
#include "utils/uuid.h"

static void error_helper(sqlite3* db, int rc);

#if !defined(SQLITE_ASCII) && !defined(SQLITE_EBCDIC)
#define SQLITE_ASCII 1
#endif

/*
* Translate a single byte of Hex into an integer.
Expand Down Expand Up @@ -227,6 +229,8 @@ sqlite_fdw_data_norm_uuid(sqlite3_context* context, int argc, sqlite3_value** ar
sqlite3_result_value(context, arg);
}

/* ********************* End of UUID SQLite extension *********************** */

/*
* ISO:SQL valid boolean values with text affinity such as Y, no, f, t, oN etc.
* will be treated as boolean like in PostgreSQL console input
Expand Down
34 changes: 29 additions & 5 deletions sqlite_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ sqlite_convert_to_pg(Form_pg_attribute att, sqlite3_value * val, AttInMetadata *
Datum d = DirectFunctionCall1(int84, Int64GetDatum((int64) i64v));
return (struct NullableDatum) {d, false};
}
case SQLITE_FLOAT: /* TODO: This code is untill mod() pushdowning fix here*/
case SQLITE_FLOAT: /* TODO: This code is untill mod() pushdowning fix here */
{
int value = sqlite3_value_int(val);

Expand Down Expand Up @@ -194,7 +194,7 @@ sqlite_convert_to_pg(Form_pg_attribute att, sqlite3_value * val, AttInMetadata *
sqlite3_int64 value = sqlite3_value_int64(val);
return (struct NullableDatum) {Int64GetDatum(value), false};
}
case SQLITE_FLOAT: /* TODO: This code is untill mod() pushdowning fix here*/
case SQLITE_FLOAT: /* TODO: This code is untill mod() pushdowning fix here */
{
double value = sqlite3_value_double(val);
Datum d = DirectFunctionCall1(dtoi8, Float8GetDatum((float8) value));
Expand Down Expand Up @@ -238,7 +238,15 @@ sqlite_convert_to_pg(Form_pg_attribute att, sqlite3_value * val, AttInMetadata *
case SQLITE3_TEXT:
{
if (value_byte_size_blob_or_utf8)
sqlite_value_to_pg_error();
{
/* TODO: NaN partially only detecting
* const char* text_value = (const char*) sqlite3_value_text(val);
* if (strcasecmp(text_value, "NaN") == 0)
* return (struct NullableDatum) {Float8GetDatum(NAN), false};
* else
*/
sqlite_value_to_pg_error();
}
else
pg_column_void_text_error();
break;
Expand All @@ -265,7 +273,15 @@ sqlite_convert_to_pg(Form_pg_attribute att, sqlite3_value * val, AttInMetadata *
case SQLITE3_TEXT:
{
if (value_byte_size_blob_or_utf8)
sqlite_value_to_pg_error();
{
/* TODO: NaN partially only detecting
* const char* text_value = (const char*) sqlite3_value_text(val);
* if (strcasecmp(text_value, "NaN") == 0)
* return (struct NullableDatum) {Float8GetDatum(NAN), false};
* else
*/
sqlite_value_to_pg_error();
}
else
pg_column_void_text_error();
break;
Expand Down Expand Up @@ -338,7 +354,15 @@ sqlite_convert_to_pg(Form_pg_attribute att, sqlite3_value * val, AttInMetadata *
case SQLITE3_TEXT:
{
if (value_byte_size_blob_or_utf8)
sqlite_value_to_pg_error();
{
/* TODO: NaN partially only detecting
* const char* text_value = (const char*) sqlite3_value_text(val);
* if (strcasecmp(text_value, "NaN") == 0)
* return (struct NullableDatum) {Float8GetDatum(NAN), false};
* else
*/
sqlite_value_to_pg_error();
}
else
pg_column_void_text_error();
break;
Expand Down

0 comments on commit cbde7e8

Please sign in to comment.