CLIP_DLLEXPORT C_object* _fetch_co_arg(ClipMachine* cm) { C_object* cobj; if (_clip_parinfo(cm,1)==NUMERIC_t) { cobj = (C_object*)_clip_fetch_c_item(cm,_clip_parni(cm,1), _C_ITEM_TYPE_WIDGET); } else { if (_clip_parinfo(cm,1)==MAP_t) { double h; _clip_mgetn(cm, _clip_spar(cm,1), HASH_HANDLE, &h); cobj = (C_object *) _clip_fetch_c_item(cm, (int) h, _C_ITEM_TYPE_WIDGET); } else { _clip_trap_err(cm,EG_ARG,0,0,"CLIP_GTK_SYSTEM", EG_ARG,"Bad object descriptor"); return NULL; } } if(!cobj) { _clip_trap_err(cm,EG_ARG,0,0,"CLIP_GTK_SYSTEM", EG_ARG,"Bad object descriptor"); return NULL; } return cobj; }
int ms_start(ClipMachine* mp,SQLCONN* c,const char* p1,const char* p2){ MS_CONN* conn = (MS_CONN*)c; int status; if(conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } if(p1){ char str[256]; snprintf(str,sizeof(str),"set transaction isolation level %s",p1); status = mysql_query(conn->conn,str); if(status){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT,mysql_error(conn->conn)); return 1; } } status = mysql_query(conn->conn,"begin"); if(status){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT,mysql_error(conn->conn)); return 1; } conn->at = 1; return 0; }
/* ************************************************************************* */ int pg_lo_seek(ClipMachine* mp, SQLCONN* c, int oid_fd, int offset, int whence){ PG_CONN *conn = (PG_CONN*)c; int rt; if(!conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } switch(whence){ case SQLBLOB_SEEKTOP: whence = SEEK_SET; break; case SQLBLOB_SEEKCURRENT: whence = SEEK_CUR; break; case SQLBLOB_SEEKBOTTOM: whence = SEEK_END; break; default: _clip_trap_err(mp,0,0,0,subsys,ER_START,er_blob_seek); return 1; } rt = lo_lseek(conn->conn, oid_fd, offset, whence); if (rt < 0){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_blob_seek); return 1; } _clip_retni(mp,(unsigned int) rt); return 0; }
int clip_SQLPREPARE(ClipMachine * ClipMachineMemory) { SQLCONN *conn = (SQLCONN *) _clip_fetch_c_item(ClipMachineMemory, _clip_parni(ClipMachineMemory, 1), _C_ITEM_TYPE_SQL); char *sql = _clip_parc(ClipMachineMemory, 2); int res; if (!conn) { _clip_trap_err(ClipMachineMemory, 0, 0, 0, subsys, ER_NOCONNECT, er_noconnect); return 1; } if (!sql) { _clip_trap_err(ClipMachineMemory, 0, 0, 0, subsys, ER_NOSQL, er_nosql); return 1; } if ((res = conn->vtbl->prepare(ClipMachineMemory, conn, sql)) == -1) return 1; _clip_retni(ClipMachineMemory, res); return 0; }
int pg_start(ClipMachine* mp,SQLCONN* c,const char* p1,const char* p2){ PG_CONN* conn = (PG_CONN*)c; PGresult* res; if(conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } res = PQexec(conn->conn,"begin"); if(PQresultStatus(res) != PGRES_COMMAND_OK){ _clip_trap_err(mp,0,0,0,subsys,ER_START, PQresultErrorMessage(res)); return 1; } if(p1){ char str[256]; snprintf(str,sizeof(str),"set transaction isolation level %s",p1); res = PQexec(conn->conn,str); if(PQresultStatus(res) != PGRES_COMMAND_OK){ _clip_trap_err(mp,0,0,0,subsys,ER_START, PQresultErrorMessage(res)); return 1; } } conn->at = 1; return 0; }
int pg_refresh(ClipMachine* mp,SQLROWSET* rs,SQLSTMT* s,ClipVar* ap){ PG_ROWSET* rowset = (PG_ROWSET*)rs; PG_STMT* stmt = (PG_STMT*)s; int i,j,len; void** rec; pg_bindpars(stmt,ap); if(!stmt->sql){ _clip_trap_err(mp,0,0,0,subsys,ER_NOSQL,er_nosql); return -1; } stmt->res = PQexec(stmt->conn->conn,stmt->sql); if(!stmt->res){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT, PQresultErrorMessage(stmt->res)); return -1; } if(PQresultStatus(stmt->res)!=PGRES_TUPLES_OK){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSELECT, PQresultErrorMessage(stmt->res)); return -1; } if(PQntuples(stmt->res)>0){ rec = malloc(sizeof(void*)*rowset->nfields); for(j=0;j<rowset->nfields;j++){ if(!PQgetisnull(stmt->res,0,j)){ len = PQgetlength(stmt->res,0,j); if(rowset->binary){ rec[j] = malloc(len+4); *((int*)(rec[j])) = len; memcpy(((char*)rec[j])+4,PQgetvalue(stmt->res,0,j),len); } else { rec[j] = malloc(len+1); memcpy(rec[j],PQgetvalue(stmt->res,0,j),len); ((char*)(rec[j]))[len] = 0; } } else { rec[j] = NULL; } } for(i=0;i<rowset->nfields;i++) free(rowset->data[rowset->recno-1][i]); free(rowset->data[rowset->recno-1]); rowset->data[rowset->recno-1] = rec; } else { pg_delete((SQLROWSET*)rowset); rowset->lastrec--; if(rowset->recno > rowset->lastrec) rowset->recno = rowset->lastrec; } return 0; }
/* ************************************************************************* */ int pg_lo_export(ClipMachine* mp, SQLCONN* c, unsigned int OID, const char *filename){ PG_CONN *conn = (PG_CONN*)c; if(!conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } if (lo_export(conn->conn, OID, filename) > 0){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_blob_export); return 1; } return 0; }
int ms_createrowset(ClipMachine* mp,SQLROWSET* rs,ClipVar* ap,ClipVar* idname,const char* gen_idSQL){ MS_ROWSET* rowset = (MS_ROWSET*)rs; MS_STMT* stmt = rowset->stmt; MS_CONN* conn = rowset->conn; int i; int status; MYSQL_FIELD *fields; ms_bindpars(stmt,ap); rowset->rowset_item = _clip_store_c_item(mp,rowset,_C_ITEM_TYPE_SQL,destroy_ms_rowset); if(!stmt->sql){ _clip_trap_err(mp, 0, 0, 0, subsys, ER_NOSQL, er_nosql); return 1; } status = mysql_query(conn->conn,stmt->sql); if(status){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT,mysql_error(conn->conn)); return 1; } stmt->res = mysql_use_result(conn->conn); rowset->unknownrows = 1; rowset->lastrec = mysql_num_rows(stmt->res); rowset->nfields = mysql_field_count(conn->conn); if(!rowset->nfields){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSELECT,mysql_error(conn->conn)); return 1; } rowset->fields = calloc(1,rowset->nfields * sizeof(SQLFIELD)); fields = mysql_fetch_fields(stmt->res); for(i=0;i<rowset->nfields;i++){ strncpy(rowset->fields[i].name, fields[i].name, MAXFIELDNAME); rowset->fields[i].name[MAXFIELDNAME] = 0; rowset->fields[i].type = fields[i].type; rowset->fields[i].ctype[0] = _ms_ctype(rowset->fields[i].type); rowset->fields[i].len = fields[i].length; rowset->fields[i].dec = fields[i].decimals; rowset->fields[i].ops = 0; rowset->fields[i].unsign = fields[i].flags & UNSIGNED_FLAG; rowset->fields[i].notnull = fields[i].flags & NOT_NULL_FLAG; rowset->fields[i].binary = fields[i].flags & BINARY_FLAG; if (fields[i].flags & AUTO_INCREMENT_FLAG) { rowset->id = i; } } rowset->data = calloc(rowset->lastrec,sizeof(void*)); return 0; }
/* ************************************************************************* */ int pg_lo_unlink(ClipMachine* mp, SQLCONN* c, unsigned int OID){ PG_CONN *conn = (PG_CONN*)c; int rt; if(!conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } rt = lo_unlink(conn->conn, OID); if (rt < 0){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_blob_unlink); return 1; } return 0; }
int ms_refresh(ClipMachine* mp,SQLROWSET* rs,SQLSTMT* s,ClipVar* ap){ MS_ROWSET *rowset = (MS_ROWSET*)rs; MS_STMT* stmt = (MS_STMT*)s; int i; unsigned long *lens; void **rec; int status; MYSQL_ROW row; ms_bindpars(stmt,ap); if(!stmt->sql){ _clip_trap_err(mp, 0, 0, 0, subsys, ER_NOSQL, er_nosql); return -1; } status = mysql_query(stmt->conn->conn,stmt->sql); if(status){ _clip_trap_err(mp, 0, 0, 0, subsys, ER_BADSTATEMENT, mysql_error(stmt->conn->conn)); return -1; } stmt->res = mysql_use_result(stmt->conn->conn); row = mysql_fetch_row(stmt->res); if(row){ rec = malloc(sizeof(void *) * rowset->nfields); lens = mysql_fetch_lengths(stmt->res); for(i=0;i<rowset->nfields;i++){ if(row[i]){ rec[i] = malloc(lens[i] + 4); *((int *) (rec[i])) = (int) lens[i]; memcpy(((char *) rec[i]) + 4, row[i], lens[i]); } else { rec[i] = NULL; } if(rowset->data[rowset->recno-1][i]) free(rowset->data[rowset->recno-1][i]); } free(rowset->data[rowset->recno-1]); rowset->data[rowset->recno-1] = rec; } else { ms_delete((SQLROWSET*)rowset); rowset->lastrec--; if(rowset->recno > rowset->lastrec) rowset->recno = rowset->lastrec; } return 0; }
int clip_SQLSETVALUE(ClipMachine * ClipMachineMemory) { SQLROWSET *rowset = (SQLROWSET *) _clip_fetch_c_item(ClipMachineMemory, _clip_parni(ClipMachineMemory, 1), _C_ITEM_TYPE_SQL); int fieldno = _clip_parni(ClipMachineMemory, 2) - 1; int len, k; char *value = _clip_parcl(ClipMachineMemory, 3, &len); SQLORDER *order; if (!rowset) { _clip_trap_err(ClipMachineMemory, 0, 0, 0, subsys, ER_NOROWSET, er_norowset); return 1; } if (fieldno < 0 || fieldno >= rowset->nfields) { _clip_trap_err(ClipMachineMemory, 0, 0, 0, subsys, ER_NOFIELD, er_nofield); return 1; } if (!value) len = 0; if (!rowset->newrec) { for (k = 0; k < rowset->ntags; k++) { order = (SQLORDER *) HashTable_fetch(rowset->orders, rowset->taghashes[k]); if (sql_searchtree(ClipMachineMemory, rowset, order)) return 1; if (sql_orderdel(ClipMachineMemory, rowset, rowset->taghashes[k])) return 1; } } rowset->conn->vtbl->setvalue(rowset, fieldno, value, len); if (!rowset->newrec) { for (k = 0; k < rowset->ntags; k++) { order = (SQLORDER *) HashTable_fetch(rowset->orders, rowset->taghashes[k]); if (sql_orderadd(ClipMachineMemory, rowset, rowset->taghashes[k])) return 1; } } return 0; }
/* ************************************************************************* */ int pg_lo_close(ClipMachine* mp, SQLCONN* c, int oid_fd){ PG_CONN *conn = (PG_CONN*)c; int rt; if(!conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } rt = lo_close(conn->conn, oid_fd); if (rt < 0){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_blob_close); return 1; } return 0; }
int pg_createconn(ClipMachine* mp){ char* pghost = _clip_parc(mp,2); char* pgport = _clip_parc(mp,3); char* login = _clip_parc(mp,4); char* pwd = _clip_parc(mp,5); char* dbName = _clip_parc(mp,6); char* pgtty = _clip_parc(mp,7); char* pgoptions = _clip_parc(mp,8); char* trpars = _clip_parc(mp,10); PGconn* tmpconn; PGresult* res; PG_CONN* conn; char str[256]; tmpconn = PQsetdbLogin(pghost,pgport,pgoptions,pgtty,dbName,login,pwd); if(PQstatus(tmpconn)!=CONNECTION_OK){ _clip_trap_err(mp,0,0,0,subsys,ER_CONNECT,PQerrorMessage(tmpconn)); return -1; } conn = malloc(sizeof(PG_CONN)); memset(conn,0,sizeof(PG_CONN)); conn->conn = tmpconn; conn->vtbl = &vtbl; res = PQexec(tmpconn,"SET DATESTYLE='ISO'"); if(PQresultStatus(res) != PGRES_COMMAND_OK){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT, PQresultErrorMessage(res)); return -1; } if(!trpars) trpars = _clip_fetch_item(mp, _clip_hashstr("PG_ISOLATION_LEVEL")); if(!trpars) trpars = _clip_fetch_item(mp, _clip_hashstr("SQL_ISOLATION_LEVEL")); if(trpars){ snprintf(str,sizeof(str),"set session characteristics as transaction isolation level %s",trpars); res = PQexec(tmpconn,str); if(PQresultStatus(res) != PGRES_COMMAND_OK){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT, PQresultErrorMessage(res)); return -1; } } PQsetNoticeProcessor(tmpconn, notice_processor, NULL); return _clip_store_c_item(mp,(void*)conn,_C_ITEM_TYPE_SQL,destroy_pg_conn); }
int clip_CHARMIX(ClipMachine * ClipMachineMemory) { int l1, l2, i; unsigned char *ret; unsigned char *str1 = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1); unsigned char *str2 = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2); if (str1 == NULL || str2 == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHARMIX"); } if (l2 == 0) { _clip_retcn(ClipMachineMemory, (char *) str1, l1); return 0; } ret = malloc(l1 * 2 + 1); for (i = 0; i < l1; i++) { ret[i * 2] = str1[i % l1]; ret[i * 2 + 1] = str2[i % l2]; } ret[l1 * 2] = 0; _clip_retcn_m(ClipMachineMemory, (char *) ret, l1 * 2); return 0; }
int odbc_error(ClipMachine* cm,SQLLocale* loc,SQLHENV henv,SQLHDBC hdbc,SQLHSTMT hstmt,int line,const char* er_){ char state[6]; SQLINTEGER native; char error[MAX_ERROR_MESSAGE_LEN+1]; SQLSMALLINT errlen; char err[MAX_ERROR_MESSAGE_LEN+1]; int u; char *r,*c,*e; u = SQLError(henv,hdbc,hstmt,state,&native,error,MAX_ERROR_MESSAGE_LEN,&errlen); while((r = strchr(error,';'))) *r = ' '; while((r = strchr(error,'\n'))) *r = ';'; while((r = strchr(error,'\r'))) *r = ' '; if(native) snprintf(err,MAX_ERROR_MESSAGE_LEN,";%s; SQLSTATE: %s : Native error %d;%s;", er_,state,(int)native,error); else snprintf(err,MAX_ERROR_MESSAGE_LEN,";%s; SQLSTATE: %s;%s;", er_,state,error); if(loc){ c = err; e = err+strlen(err); for(;c<e;c++) if(*c&0x80) *c = loc->read[*c&0x7f]; } _clip_trap_err(cm, 0, 0, 0, __FILE__, line, err); return -1; }
int clip_WORDONLY(ClipMachine * ClipMachineMemory) { int l1, l2, i = 0; short *ret, *e1, *end1, *e2, *end2; short *str1 = (short *) _clip_parcl(ClipMachineMemory, 1, &l1); short *str2 = (short *) _clip_parcl(ClipMachineMemory, 2, &l2); if (str1 == NULL || str2 == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "WORDONLY"); } l1 = l1 >> 1; l2 = l2 >> 1; ret = malloc((l2 + 1) * 2); for (e2 = str2, end2 = str2 + l2; e2 < end2; e2++) { for (e1 = str1, end1 = str1 + l1; e1 < end1 && *e2 != *e1; e1++); if (*e1 != *e2) continue; ret[i] = *e2; i++; } ret[i] = 0; _clip_retcn_m(ClipMachineMemory, (char *) ret, i * 2); return 0; }
int clip_BEFORATNUM(ClipMachine * ClipMachineMemory) { int l, l1, l2; unsigned char *ret, *beg; unsigned char *sstr = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1); unsigned char *str = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2); int count = _clip_parni(ClipMachineMemory, 3); int ignore = _clip_parni(ClipMachineMemory, 4); if (sstr == NULL || str == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "BEFORATNUM"); } beg = _clip_atmupa(ClipMachineMemory, sstr, l1, str, l2, ignore, count, 1); l = beg - str; ret = malloc(l + 1); memcpy(ret, str, l); ret[l] = 0; _clip_retcn_m(ClipMachineMemory, (char *) ret, l); return 0; }
int clip_CHARSWAP(ClipMachine * ClipMachineMemory) { int l, i; unsigned char *ret, ch; unsigned char *str = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l); int rset = (*(char *) (_clip_fetch_item(ClipMachineMemory, HASH_csetref)) == 't'); if (str == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHARSWAP"); } ret = str; ret = malloc(l + 1); for (i = 0; i < l; i += 2) { if (i < l - 1) { ch = str[i]; ret[i] = str[i + 1]; ret[i + 1] = ch; } else ret[i] = str[i]; } ret[l] = 0; if (rset && _clip_par_isref(ClipMachineMemory, 1)) _clip_par_assign_str(ClipMachineMemory, 1, (char *) ret, l); _clip_retcn_m(ClipMachineMemory, (char *) ret, l); return 0; }
int clip_STRSWAP(ClipMachine * ClipMachineMemory) { int l1, l2, l, i; unsigned char ch; unsigned char *s1 = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1); unsigned char *s2 = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2); if (s1 == NULL || s2 == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "STRSWAP"); } l = l1 < l2 ? l1 : l2; for (i = 0; i < l; i++) { ch = s1[i]; s1[i] = s2[i]; s2[i] = ch; } _clip_retc(ClipMachineMemory, ""); return 0; }
int clip_EVALA(ClipMachine * ClipMachineMemory) { int parcount; ClipVar *params; ClipVar *bp = _clip_par(ClipMachineMemory, 1); ClipVar *ap = _clip_par(ClipMachineMemory, 2); if (!bp || (bp->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType != CCODE_type_of_ClipVarType && bp->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType != PCODE_type_of_ClipVarType)) return 0; if (!ap || ap->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType != ARRAY_type_of_ClipVarType) { int r; r = _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "EVALA"); return _clip_call_errblock(ClipMachineMemory, r); } parcount = ap->ClipArrVar_a_of_ClipVar.count_of_ClipArrVar; params = ap->ClipArrVar_a_of_ClipVar.ClipVar_items_of_ClipArrVar; //_clip_clip(ClipMachineMemory, funcname, parcount, params, retVal); return _clip_eval(ClipMachineMemory, bp, parcount, params, RETPTR(ClipMachineMemory)); }
int clip_CLIPA(ClipMachine * ClipMachineMemory) { char *funcname = _clip_parc(ClipMachineMemory, 1); int parcount; ClipVar *params, *retVal = RETPTR(ClipMachineMemory); ClipVar *ap = _clip_par(ClipMachineMemory, 2); if (!funcname || !ap || ap->ClipType_t_of_ClipVar.ClipVartype_type_of_ClipType != ARRAY_type_of_ClipVarType) { int r; r = _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CLIPA"); return _clip_call_errblock(ClipMachineMemory, r); } parcount = ap->ClipArrVar_a_of_ClipVar.count_of_ClipArrVar; params = ap->ClipArrVar_a_of_ClipVar.ClipVar_items_of_ClipArrVar; _clip_clip(ClipMachineMemory, funcname, parcount, params, retVal); return 0; }
int clip_PG_IN_DATE(ClipMachine* mp){ PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item( mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL); char* date; int len; if(!rowset){ _clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset); return 1; } if(rowset->binary){ date = _clip_parcl(mp,2,&len); if(date){ _clip_retdj(mp,*((int*)date)+2451545); // 2451545 - julian date } // for 01/01/2000 } else { int m,d,y; date = _clip_parc(mp,2); if(date){ y = atoi(date); m = atoi(date+5); d = atoi(date+8); _clip_retdc(mp,y,m,d); } else { _clip_retdj(mp,0); } } return 0; }
int clip_CHMOD(ClipMachine * ClipMachineMemory) { int lp = 0, *err = NULL; char buf[PATH_MAX]; char *fname = _clip_parc(ClipMachineMemory, 1); _clip_retl(ClipMachineMemory, 1); err = _clip_fetch_item(ClipMachineMemory, HASH_ferror); *err = 0; if (_clip_parinfo(ClipMachineMemory, 2) == CHARACTER_type_of_ClipVarType) lp = _clip_fileStrModeToNumMode(_clip_parc(ClipMachineMemory, 2)); if (_clip_parinfo(ClipMachineMemory, 2) == NUMERIC_type_of_ClipVarType) lp = _clip_parni(ClipMachineMemory, 2); if (fname == NULL || lp == 0) { _clip_retl(ClipMachineMemory, 0); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHMOD"); } _clip_translate_path(ClipMachineMemory, fname, buf, sizeof(buf)); if (chmod(buf, lp) == 0) return 0; _clip_retl(ClipMachineMemory, 0); *err = errno; return 0; }
int clip_PG_IN_DATETIME(ClipMachine* mp){ PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item( mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL); char* date; long dd,tt; if(!rowset){ _clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset); return 1; } if(rowset->binary){ double d; int l; date = _clip_parcl(mp,2,&l); d = *(double*)date; dd = _clip_jdate(1,1,2000)+d/(24*60*60); tt = ((long long)d*1000) % (24*60*60*1000); if(tt < 0) tt += 24*60*60*1000; _clip_retdtj(mp,dd,tt); } else { int l; date = _clip_parcl(mp,2,&l); _pg_in_iso_datetime(date,l,&dd,&tt); _clip_retdtj(mp,dd,tt); } return 0; }
/* ************************************************************************* */ int pg_lo_tell(ClipMachine* mp, SQLCONN* c, int oid_fd){ PG_CONN *conn = (PG_CONN*)c; int rt; if(!conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_start); return 1; } rt = lo_tell(conn->conn, oid_fd); if (rt < 0){ _clip_trap_err(mp,0,0,0,subsys,ER_START,er_blob_tell); return 1; } _clip_retni(mp,(unsigned int) rt); return 0; }
int clip_BITTOC(ClipMachine * mp) { unsigned int Num = _clip_parni(mp, 1); int LenPattern; char *BitPattern = _clip_parcl(mp, 2, &LenPattern); char *p, res[] = " "; unsigned int Mask; int Len = _clip_parinfo(mp, 0), RealLen; int t1 = _clip_parinfo(mp, 1); int t2 = _clip_parinfo(mp, 2); if (Len < 2 || t1 != NUMERIC_t || t2 != CHARACTER_t) { _clip_retc(mp, ""); return _clip_trap_err(mp, EG_ARG, 0, 0, __FILE__, __LINE__, "BITTOC"); } if (LenPattern > 16) LenPattern = 16; if (_clip_parl(mp, 3)) { for (RealLen = LenPattern, Len = 0, Mask = 1 << (LenPattern - 1); Len < LenPattern; Mask >>= 1, Len++) if (Num & Mask) res[Len] = BitPattern[Len]; } else { for (RealLen = 0, p = res, Len = 0, Mask = 1 << (LenPattern - 1); Len < LenPattern; Mask >>= 1, Len++)
int clip_CHARAND(ClipMachine * ClipMachineMemory) { int l1, l2; unsigned char *ret, *e, *end, *e2, *end2; unsigned char *str = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1); unsigned char *s = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2); int rset = (*(char *) (_clip_fetch_item(ClipMachineMemory, HASH_csetref)) == 't'); if (str == NULL || s == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHARAND"); } ret = malloc(l1 + 1); memcpy(ret, str, l1); ret[l1] = 0; end2 = s + l2; for (e = ret, end = ret + l1; e < end;) for (e2 = s; e2 < end2 && e < end; e++, e2++) *e = (*e & *e2); if (rset && _clip_par_isref(ClipMachineMemory, 1)) _clip_par_assign_str(ClipMachineMemory, 1, (char *) ret, l1); _clip_retcn_m(ClipMachineMemory, (char *) ret, l1); return 0; }
int clip_PG_OUT_TIMESTAMP(ClipMachine* mp){ PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item( mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL); int totext = _clip_parl(mp,3); struct tm time; time_t bindate; char* date; int len; if(!rowset){ _clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset); return 1; } if((!totext)&&rowset->binary){ memset(&time,0,sizeof(time)); _clip_pardc(mp,2,&time.tm_year,&time.tm_mon,&time.tm_mday,&time.tm_wday); time.tm_year -= 1900; time.tm_mon--; bindate = mktime(&time); _clip_retcn(mp,(char*)(&bindate),4); } else { date = _clip_parcl(mp,2,&len); _clip_retc(mp,date); // char str[25]; // _pg_out_date(mp,str,rowset->conn->datestyle,rowset->conn->textdate,_clip_pardj(mp,2)); // _clip_retc(mp,str); } return 0; }
int ms_rollback(ClipMachine* mp,SQLCONN* c){ MS_CONN* conn = (MS_CONN*)c; int status; if(!conn->at){ _clip_trap_err(mp,0,0,0,subsys,ER_COMMIT,er_commit); return 1; } conn->at = 0; status = mysql_query(conn->conn,"rollback"); if(status){ _clip_trap_err(mp,0,0,0,subsys,ER_BADSTATEMENT,mysql_error(conn->conn)); return 1; } return 0; }
int clip_CHARREM(ClipMachine * ClipMachineMemory) { int l, l1, l2, i; unsigned char *ret, *e, *end, *s; unsigned char *str1 = (unsigned char *) _clip_parcl(ClipMachineMemory, 1, &l1); unsigned char *str2 = (unsigned char *) _clip_parcl(ClipMachineMemory, 2, &l2); if (str1 == NULL || str2 == NULL) { _clip_retc(ClipMachineMemory, ""); return _clip_trap_err(ClipMachineMemory, EG_ARG, 0, 0, __FILE__, __LINE__, "CHARREM"); } l = l2; ret = malloc(l + 1); s = calloc(256, 1); for (e = str1, end = str1 + l1; e < end; e++) s[(int) (*e)] = 1; for (i = 0, e = str2, end = str2 + l2; e < end; e++) { if (s[(int) (*e)] == 1) continue; ret[i] = *e; i++; } free(s); ret[i] = 0; _clip_retcn_m(ClipMachineMemory, (char *) ret, i); return 0; }