IoObject *IoBox_print(IoBox *self, IoObject *locals, IoMessage *m) { /*doc Box print Prints a string representation of the receiver to the standard output. */ IoState_print_(IOSTATE, "Box clone set("); IoSeq_print(DATA(self)->origin, locals, m); IoState_print_(IOSTATE, ", "); IoSeq_print(DATA(self)->size, locals, m); IoState_print_(IOSTATE, ")"); return self; }
IoObject *IoSQLite3_execWithCallback(IoSQLite3 *self, IoObject *locals, IoMessage *m, IoSymbol *s, ResultRowCallback *callback) { IoList *results; if (!DATA(self)->db) { IoSQLite3_justOpen(self); if (!DATA(self)->db) { return IONIL(self); } } DATA(self)->results = IOREF(IoList_new(IOSTATE)); if (DATA(self)->debugOn) { IoState_print_(IOSTATE, "*** %s ***\n", CSTRING(s)); } { char *zErrMsg; sqlite3_exec(DATA(self)->db, CSTRING(s), callback, self, &zErrMsg); IoSQLite3_showError(self); } results = DATA(self)->results; DATA(self)->results = NULL; return results; }
IoObject *IoSQLite_open(IoSQLite *self, IoObject *locals, IoMessage *m) { /*doc SQLite open(optionalPathString) Opens the database.Returns self on success or nil upon failure. If the databse is locked, "yield" will be called until it is accessable or timeoutSeconds has expired. */ char *zErrMsg; if (DATA(self)->debugOn) { IoState_print_(IOSTATE, "IoSQLite opening '%s'\n", CSTRING(DATA(self)->path)); } DATA(self)->db = sqlite_open(CSTRING(DATA(self)->path), 0, &zErrMsg); if (!DATA(self)->db) { IoSQLite_error_(self, zErrMsg); } else { IoSQLite_error_(self, ""); } sqlite_busy_handler(DATA(self)->db, IoSQLite_busyHandler, self); sqlite_busy_timeout(DATA(self)->db, DATA(self)->timeoutSeconds*1000); return self; }
void IoMessage_print(IoMessage *self) { UArray *ba = IoMessage_description(self); //printf("%s\n", UArray_asCString(ba)); IoState_print_(IOSTATE, UArray_asCString(ba)); UArray_free(ba); }
void IoNumber_print(IoNumber *self) { double d = DATA(self); char s[128]; IoNumber_Double_intoCString_(d, s, 127); IoState_print_(IOSTATE, "%s", s); }
void IoSQLite_error_(IoSQLite *self, char *error) { DATA(self)->error = strcpy((char *)realloc(DATA(self)->error, strlen(error)+1), error); if (strlen(DATA(self)->error) && DATA(self)->debugOn) { IoState_print_(IOSTATE, "*** IoSQLite error '%s' ***\n", DATA(self)->error); } }
IO_METHOD(IoNumber, printNumber) { /*doc Number print Prints the number. */ char *s = IoNumber_asAllocedCString(self); IoState_print_((IoState *)IOSTATE, s); io_free(s); return self; }
void IoSQLite3_showError(IoSQLite3 *self) { int status = sqlite3_errcode(DATA(self)->db); if (status != SQLITE_OK) { const char *error = IoSQLite3_error(self); if (DATA(self)->debugOn) { IoState_print_(IOSTATE, "*** IoSQLite3 error '%s' ***\n", error); } } }
IoObject *IoSQLite_execWithCallback(IoSQLite *self, IoObject *locals, IoMessage *m, IoSymbol *s, ResultRowCallback *callback) { IoList *results; if (!DATA(self)->db) { IoSQLite_open(self, locals, m); if (!DATA(self)->db) { return IONIL(self); } } DATA(self)->results = IOREF(IoList_new(IOSTATE)); if (DATA(self)->debugOn) { IoState_print_(IOSTATE, "*** %s ***\n", CSTRING(s)); } { char *zErrMsg; int rc = sqlite_exec(DATA(self)->db, CSTRING(s), callback, self, &zErrMsg); if (rc != SQLITE_OK) { IoSQLite_error_(self, zErrMsg); IoState_error_(IOSTATE, m, zErrMsg); } else { IoSQLite_error_(self, ""); } } results = DATA(self)->results; DATA(self)->results = NULL; return results; }
void IoMessage_printWithReturn(IoMessage *self) { IoMessage_print(self); IoState_print_(IOSTATE, "\n"); }