Skip to content

Commit

Permalink
Release "3.0.10": Fix issues #12, #13, and #14.
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 70747c8d1c4e7bf176bec8cfb9d3cac3e64a696e7df0b1e3712d3f6b952164c3
  • Loading branch information
pmacdona committed May 11, 2020
1 parent cc29c8c commit 20ff8e2
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 65 deletions.
38 changes: 20 additions & 18 deletions lib/Jsish.jsi
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,28 @@ function Jsi_SqlValues(name:string, val:object) {
return 'VALUES($'+name+'('+val.keys().join('),$'+name+'(')+'))';
}

// Modify table, adding missing columns that are in data to support up/down grading.
function Jsi_SchemaUpdate(db:userobj, table:string, data:object, conf:object=void) {
// Create/modify table compatible with object, adds missing columns that are in data to support up/down grading.
function Jsi_ObjToSchema(db:userobj, table:string, data:object, conf:object=void) {
var self = {};
var options = {
noCreate :false, // Create table, if not exists.
objOpts :{}, // Options for objOpts
verbose :false
};
parseOpts(self, options, conf);
var cl = {}, cols = db.query('PRAGMA table_info("'+table+'")');
if (!cols.length)
if (!cols.length) {
if (!self.noCreate)
db.query("CREATE TABLE '"+table+"' %s", {objName:'data'});
return true;
}
for (var c=0; c<cols.length; c++)
cl[cols[c].name] = cols[c];
var oo = self.objOpts;
oo.getSql = true;
var s = db.query('CREATE TABLE '+table+' %s', {objName:'data', objOpts:oo});
//oo.noCheck = true;
var fs = db.query("CREATE TABLE '"+table+"' %s", {objName:'data', objOpts:oo});
var s = fs;
s = ','+s.substr( s.indexOf('(')+1);
s = s.substr(0, s.length-2);
s +=',';
Expand All @@ -281,26 +287,22 @@ function Jsi_SchemaUpdate(db:userobj, table:string, data:object, conf:object=voi
var rec = s.substr( s.indexOf(','+i+' '));
if (!rec) throw('failed to find schema: '+i);
rec = rec.substr(1);
rec = rec.substr(0, rec.indexOf(','));
var sql = 'ALTER TABLE '+table+' ADD COLUMN '+rec;
var re = rec.indexOf(',');
if (rec[re+1] == ' ' && ((re = rec.indexOf(')', re))>=0))
re = rec.indexOf(',', re);
rec = rec.substr(0, re);
var sql = 'ALTER TABLE "'+table+'" ADD COLUMN '+rec;
puts("RR: ",sql);
if (self.verbose)
LogInfo('SCHEMA:',sql);
db.eval(sql);
cl[i] = rec;
}
// Now check if schema matches.
var t = '';
for (i in cl) {
t += ',';
if (typeof(cl[i])==='string')
t += cl[i];
else
t += (i+' '+cl[i].type+' DEFAULT '+cl[i].dflt_value);
}
t += ',';
if (s === t)
// Now check if schema matches.
/*var t = db.onecolumn("SELECT sql from sqlite_master where type='table' and name=@table");
if (fs === t)
return true;
LogWarn('Schema mismatch (possible downgrade?) in table "'+table+'":\n"'+s+'" !=\n"'+t+'"');
LogWarn('Schema mismatch (possible downgrade?) in table "'+table+'":\n"'+fs+'" !=\n"'+t+'"');*/
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/autoload.jsi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Jsi_Auto.Jsi_Run =
Jsi_Auto.Jsi_LogFile =
Jsi_Auto.Jsi_Opts =
Jsi_Auto.Jsi_SqlValues =
Jsi_Auto.Jsi_SchemaUpdate =
Jsi_Auto.Jsi_ObjToSchema =
Jsi_Auto.Jsi_Conf = 'source("'+Info.scriptDir()+'/Jsish.jsi")';
Jsi_Auto.Htmlpp = 'source("'+Info.scriptDir()+'/Htmlpp.jsi")';
Jsi_Auto.Csspp = 'source("'+Info.scriptDir()+'/Csspp.jsi")';
Expand Down
4 changes: 2 additions & 2 deletions md/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ Or if no new transation was started, do nothing. pass the exception on up the st
<tr><td>nocache</td><td><i>BOOL</i></td><td>Disable query cache.</td><td><i></i></td></tr>
<tr><td>nullvalue</td><td><i>STRKEY</i></td><td>Null string output (for non js/json mode).</td><td><i></i></td></tr>
<tr><td>objName</td><td><i>STRKEY</i></td><td>Object var name for CREATE/INSERT: replaces %s with fields in query.</td><td><i></i></td></tr>
<tr><td>objOpts</td><td><i>ARRAY</i></td><td>Options for objName. (zero or more of: <b>getSql</b>, <b>noTypes</b>, <b>noDefaults</b>, <b>nullDefaults</b>)</td><td><i></i></td></tr>
<tr><td>objOpts</td><td><i>ARRAY</i></td><td>Options for objName. (zero or more of: <b>getSql</b>, <b>noTypes</b>, <b>noDefaults</b>, <b>nullDefaults</b>, <b>noChecks</b>)</td><td><i></i></td></tr>
<tr><td>retChanged</td><td><i>BOOL</i></td><td>Query returns value of sqlite3_changed().</td><td><i></i></td></tr>
<tr><td>separator</td><td><i>STRKEY</i></td><td>Separator string (for csv and text mode).</td><td><i></i></td></tr>
<tr><td>typeCheck</td><td><i>STRKEY</i></td><td>Type check mode (warn). (one of: <b>convert</b>, <b>warn</b>, <b>error</b>, <b>disable</b>)</td><td><i></i></td></tr>
Expand Down Expand Up @@ -1235,7 +1235,7 @@ Or if no new transation was started, do nothing. pass the exception on up the st
<tr><td>nocache</td><td><i>BOOL</i></td><td>Disable query cache.</td><td><i></i></td></tr>
<tr><td>nullvalue</td><td><i>STRKEY</i></td><td>Null string output (for non js/json mode).</td><td><i></i></td></tr>
<tr><td>objName</td><td><i>STRKEY</i></td><td>Object var name for CREATE/INSERT: replaces %s with fields in query.</td><td><i></i></td></tr>
<tr><td>objOpts</td><td><i>ARRAY</i></td><td>Options for objName. (zero or more of: <b>getSql</b>, <b>noTypes</b>, <b>noDefaults</b>, <b>nullDefaults</b>)</td><td><i></i></td></tr>
<tr><td>objOpts</td><td><i>ARRAY</i></td><td>Options for objName. (zero or more of: <b>getSql</b>, <b>noTypes</b>, <b>noDefaults</b>, <b>nullDefaults</b>, <b>noChecks</b>)</td><td><i></i></td></tr>
<tr><td>retChanged</td><td><i>BOOL</i></td><td>Query returns value of sqlite3_changed().</td><td><i></i></td></tr>
<tr><td>separator</td><td><i>STRKEY</i></td><td>Separator string (for csv and text mode).</td><td><i></i></td></tr>
<tr><td>typeCheck</td><td><i>STRKEY</i></td><td>Type check mode (warn). (one of: <b>convert</b>, <b>warn</b>, <b>error</b>, <b>disable</b>)</td><td><i></i></td></tr>
Expand Down
4 changes: 2 additions & 2 deletions src/jsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#define JSI_VERSION_MAJOR 3
#define JSI_VERSION_MINOR 0
#define JSI_VERSION_RELEASE 10
#define JSI_VERSION_RELEASE 11

#define JSI_VERSION (JSI_VERSION_MAJOR + ((Jsi_Number)JSI_VERSION_MINOR/100.0) + ((Jsi_Number)JSI_VERSION_RELEASE/10000.0))

Expand Down Expand Up @@ -669,7 +669,7 @@ JSI_EXTERN void* Jsi_UserObjDataFromVar(Jsi_Interp *interp, const char *var); /*
JSI_EXTERN const char* Jsi_KeyAdd(Jsi_Interp *interp, const char *str); /*STUB = 224*/
JSI_EXTERN const char* Jsi_KeyLookup(Jsi_Interp *interp, const char *str); /*STUB = 225*/
JSI_EXTERN bool Jsi_IsReserved(Jsi_Interp *interp, const char* str, bool sql); /*STUB = 415*/
JSI_EXTERN Jsi_RC Jsi_SqlObjBinds(Jsi_Interp* interp, Jsi_DString* zStr, const char *varName, bool addTypes, bool addDefaults, bool nullDefaults); /*STUB = 417*/
JSI_EXTERN Jsi_RC Jsi_SqlObjBinds(Jsi_Interp* interp, Jsi_DString* zStr, const char *varName, bool addTypes, bool addDefaults, bool nullDefaults, bool addCheck); /*STUB = 417*/
JSI_EXTERN Jsi_RC Jsi_DatetimeFormat(Jsi_Interp *interp, Jsi_Number date, const char *fmt, int isUtc, Jsi_DString *dStr); /*STUB = 226*/
JSI_EXTERN Jsi_RC Jsi_DatetimeParse(Jsi_Interp *interp, const char *str, const char *fmt, int isUtc, Jsi_Number *datePtr, bool noMsg); /*STUB = 227*/
JSI_EXTERN Jsi_Number Jsi_DateTime(void); /*STUB = 228*/
Expand Down
20 changes: 10 additions & 10 deletions src/jsiArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,12 @@ static Jsi_RC jsi_ArrayMapCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_t

fptr = func->d.obj->d.fobj->func;
maa = (fptr->argnames?fptr->argnames->argCnt:0);
if (maa>3)
if (maa>3 || fptr->type == FC_BUILDIN)
maa = 3;
for (i = 0; i < curlen; i++) {
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):NULL);
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Expand Down Expand Up @@ -451,12 +451,12 @@ static Jsi_RC jsi_ArrayFilterCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value

fptr = func->d.obj->d.fobj->func;
maa = (fptr->argnames?fptr->argnames->argCnt:0);
if (maa>3)
if (maa>3 || fptr->type == FC_BUILDIN)
maa = 3;
for (i = 0; i < curlen; i++) {
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):NULL);
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Expand Down Expand Up @@ -533,12 +533,12 @@ static Jsi_RC jsi_ArrayForeachCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value
Jsi_Value *vobjs[3];
Jsi_Func *fptr = func->d.obj->d.fobj->func;
int maa = (fptr->argnames?fptr->argnames->argCnt:0);
if (maa>3)
if (maa>3 || fptr->type == FC_BUILDIN)
maa = 3;
for (i = 0; i < obj->arrCnt && rc == JSI_OK; i++) {
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):NULL);
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Expand Down Expand Up @@ -572,12 +572,12 @@ static Jsi_RC jsi_ArrayFindSubCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value
Jsi_Value *vobjs[3];
Jsi_Func *fptr = func->d.obj->d.fobj->func;
int maa = (fptr->argnames?fptr->argnames->argCnt:0);
if (maa>3)
if (maa>3 || fptr->type == FC_BUILDIN)
maa = 3;
for (i = 0; i < obj->arrCnt && rc == JSI_OK; i++) {
if (!obj->arr[i]) continue;
vobjs[0] = obj->arr[i];
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):NULL);
vobjs[1] = (maa>1?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[2] = _this;
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Expand Down Expand Up @@ -626,7 +626,7 @@ static Jsi_RC jsi_ArrayReduceSubCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Val
int n, rev = (op==2);
Jsi_Func *fptr = func->d.obj->d.fobj->func;
int maa = (fptr->argnames?fptr->argnames->argCnt:0);
if (maa>4)
if (maa>4 || fptr->type == FC_BUILDIN)
maa = 4;

for (n = 0, i = (rev?obj->arrCnt-1:0); (rev?i>=0:i < (int)obj->arrCnt) && rc == JSI_OK; n++, i = (rev?i-1:i+1)) {
Expand All @@ -638,7 +638,7 @@ static Jsi_RC jsi_ArrayReduceSubCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Val

vobjs[0] = ini;
vobjs[1] = obj->arr[i];
vobjs[2] = (maa>2?Jsi_ValueNewNumber(interp, i):NULL);
vobjs[2] = (maa>2?Jsi_ValueNewNumber(interp, i):interp->NullValue);
vobjs[3] = _this;
vpargs = Jsi_ValueMakeObject(interp, NULL, Jsi_ObjNewArray(interp, vobjs, maa, 0));
Jsi_IncrRefCount(interp, vpargs);
Expand Down
6 changes: 6 additions & 0 deletions src/jsiFunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,12 @@ static Jsi_RC jsi_FunctionInvoke(Jsi_Interp *interp, Jsi_Value *tocall, Jsi_Valu
/* func to call */
Jsi_Func *funcPtr = tocall->d.obj->d.fobj->func;
SIGASSERT(funcPtr, FUNC);
if (funcPtr->type == FC_BUILDIN) {
Jsi_CmdSpec *cs = funcPtr->cmdSpec;
int argc = (args ? Jsi_ValueGetLength(interp, args) : 0);
if (cs && cs->minArgs>=0 && argc<cs->minArgs)
return Jsi_LogError("too few args: expected %d", cs->minArgs);
}

/* prepare args */
if (args->vt != JSI_VT_OBJECT || !Jsi_ObjIsArray(interp, args->d.obj))
Expand Down
5 changes: 3 additions & 2 deletions src/jsiMySql.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ typedef struct QueryOpts {
static const char *trcModeStrs[] = {"eval", "delete", "prepare", "step", NULL}; // Bit-set packed into an int.
static const char *objSqlModeStrs[] = { "getSql", "noTypes", "noDefaults", "nullDefaults", NULL };
enum {mdbTMODE_EVAL=0x1, mdbTMODE_DELETE=0x2, mdbTMODE_PREPARE=0x4, mdbTMODE_STEP=0x4};
enum {OBJMODE_SQLONLY=0x1, OBJMODE_NOTYPES=0x2, OBJMODE_NODEFAULTS=0x4, OBJMODE_NULLDEFAULTS=0x8};
enum {OBJMODE_SQLONLY=0x1, OBJMODE_NOTYPES=0x2, OBJMODE_NODEFAULTS=0x4, OBJMODE_NULLDEFAULTS=0x8, OBJMODE_NOCHECKS=0x8};


typedef struct MySqlObj {
Expand Down Expand Up @@ -1623,7 +1623,8 @@ static Jsi_RC MySqlQueryCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_thi
} */
if (opts.objName) {
if (Jsi_SqlObjBinds(interp, &eStr, opts.objName, !(opts.objOpts&OBJMODE_NOTYPES),
!(opts.objOpts&OBJMODE_NODEFAULTS), (opts.objOpts&OBJMODE_NULLDEFAULTS)!=0) != JSI_OK)
!(opts.objOpts&OBJMODE_NODEFAULTS), (opts.objOpts&OBJMODE_NULLDEFAULTS)!=0,
!(opts.objOpts&OBJMODE_NOCHECKS)) != JSI_OK)
goto bail;
zSql = Jsi_DSValue(&eStr);
}
Expand Down
7 changes: 4 additions & 3 deletions src/jsiSqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ static const char *sqexecFmtStrs[] = {
static const char *mtxStrs[] = { "default", "none", "full", NULL };
static const char *trcModeStrs[] = {"eval", "delete", "prepare", "step", NULL}; // Bit-set packed into an int.
static const char *dbTypeChkStrs[] = { "convert", "warn", "error", "disable", NULL };
static const char *objSqlModeStrs[] = { "getSql", "noTypes", "noDefaults", "nullDefaults", NULL };
static const char *objSqlModeStrs[] = { "getSql", "noTypes", "noDefaults", "nullDefaults", "noChecks", NULL };
#endif

enum {OBJMODE_SQLONLY=0x1, OBJMODE_NOTYPES=0x2, OBJMODE_NODEFAULTS=0x4, OBJMODE_NULLDEFAULTS=0x8};
enum {OBJMODE_SQLONLY=0x1, OBJMODE_NOTYPES=0x2, OBJMODE_NODEFAULTS=0x4, OBJMODE_NULLDEFAULTS=0x8, OBJMODE_NOCHECKS=0x16};
enum {TMODE_EVAL=0x1, TMODE_DELETE=0x2, TMODE_PREPARE=0x4, TMODE_STEP=0x4};
typedef enum { MUTEX_DEFAULT, MUTEX_NONE, MUTEX_FULL } Mutex_Type;
typedef enum { dbTypeCheck_Cast, dbTypeCheck_Warn, dbTypeCheck_Error, dbTypeCheck_None } dbTypeCheck_Mode;
Expand Down Expand Up @@ -2648,7 +2648,8 @@ static Jsi_RC SqliteQueryCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_th
}
if (opts.objName) {
if (Jsi_SqlObjBinds(interp, &eStr, opts.objName, !(opts.objOpts&OBJMODE_NOTYPES),
!(opts.objOpts&OBJMODE_NODEFAULTS), (opts.objOpts&OBJMODE_NULLDEFAULTS)!=0) != JSI_OK)
!(opts.objOpts&OBJMODE_NODEFAULTS), (opts.objOpts&OBJMODE_NULLDEFAULTS)!=0,
!(opts.objOpts&OBJMODE_NOCHECKS)) != JSI_OK)
goto bail;
zSql = Jsi_DSValue(&eStr);
}
Expand Down
6 changes: 4 additions & 2 deletions src/jsiString.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,10 @@ static Jsi_RC StringReplaceCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_
Jsi_Value *repVal = Jsi_ValueArrayIndex(interp, args, 1+skip);
if (!Jsi_ValueIsFunction(interp, repVal))
replace_str = Jsi_ValueToString(interp, repVal, &replace_len);
else
maxArgs = repVal->d.obj->d.fobj->func->argnames->argCnt;
else {
Jsi_Func *fptr = repVal->d.obj->d.fobj->func;
maxArgs = (fptr->argnames?fptr->argnames->argCnt:0);
}
Jsi_DSInit(&dStr);

if (Jsi_ValueIsString(interp, seq)) {
Expand Down
6 changes: 3 additions & 3 deletions src/jsiStubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#endif


#define JSI_STUBS_MD5 "d32d2f3a25ef2f1bb91a706989687883"
#define JSI_STUBS_MD5 "245bfc701de9f6aaafbe9462645dc362"

#undef JSI_EXTENSION_INI
#define JSI_EXTENSION_INI Jsi_Stubs *jsiStubsPtr = NULL;
Expand Down Expand Up @@ -445,7 +445,7 @@ typedef struct Jsi_Stubs {
void(*_Jsi_IterGetKeys)(Jsi_Interp *interp, Jsi_Value *target, Jsi_IterObj *iterobj, int depth);
bool(*_Jsi_IsReserved)(Jsi_Interp *interp, const char* str, bool sql);
bool(*_Jsi_StrIsAlnum)(const char *cp);
Jsi_RC(*_Jsi_SqlObjBinds)(Jsi_Interp* interp, Jsi_DString* zStr, const char *varName, bool addTypes, bool addDefaults, bool nullDefaults);
Jsi_RC(*_Jsi_SqlObjBinds)(Jsi_Interp* interp, Jsi_DString* zStr, const char *varName, bool addTypes, bool addDefaults, bool nullDefaults, bool addCheck);
Jsi_RC(*_Jsi_UserObjName)(Jsi_Interp *interp, Jsi_Value *v, Jsi_DString *dStr);
void *endPtr;
} Jsi_Stubs;
Expand Down Expand Up @@ -1293,7 +1293,7 @@ extern Jsi_Stubs* jsiStubsPtr;
#define Jsi_IterGetKeys(n0,n1,n2,n3) JSISTUBCALL(jsiStubsPtr, _Jsi_IterGetKeys(n0,n1,n2,n3))
#define Jsi_IsReserved(n0,n1,n2) JSISTUBCALL(jsiStubsPtr, _Jsi_IsReserved(n0,n1,n2))
#define Jsi_StrIsAlnum(n0) JSISTUBCALL(jsiStubsPtr, _Jsi_StrIsAlnum(n0))
#define Jsi_SqlObjBinds(n0,n1,n2,n3,n4,n5) JSISTUBCALL(jsiStubsPtr, _Jsi_SqlObjBinds(n0,n1,n2,n3,n4,n5))
#define Jsi_SqlObjBinds(n0,n1,n2,n3,n4,n5,n6) JSISTUBCALL(jsiStubsPtr, _Jsi_SqlObjBinds(n0,n1,n2,n3,n4,n5,n6))
#define Jsi_UserObjName(n0,n1,n2) JSISTUBCALL(jsiStubsPtr, _Jsi_UserObjName(n0,n1,n2))

#endif
Expand Down
Loading

0 comments on commit 20ff8e2

Please sign in to comment.