int p_session_start( /* + */ value v_session, type t_session, /* + */ value v_username, type t_username, /* + */ value v_host, type t_host, /* + */ value v_password, type t_password, /* + */ value v_opts, type t_opts ) { session_t * session; Get_Typed_Object(v_session,t_session,&session_handle_tid,session); Check_String(t_username); Check_String(t_host); Check_String(t_password); Check_Structure(t_opts); if ( session_start( session, StringStart(v_username), StringStart(v_host), StringStart(v_password), v_opts) ) Bip_Error(dbi_errno); Succeed; }
int p_session_sql_dml( /* + */ value v_session, type t_session, /* + */ value v_SQL, type t_SQL, /* - */ value v_rows, type t_rows ) { session_t * session; cursor_t * cursor; char * SQL; word rows, *prows; int res; Check_String(t_SQL); Check_Output_Integer(t_rows); Get_Typed_Object(v_session,t_session,&session_handle_tid,session); cursor = session_sql_prepare(session, StringStart(v_SQL), StringLength(v_SQL), 0); if (NULL == cursor) Bip_Error(dbi_errno); if (res = cursor_sql_execute(cursor, 1)) { cursor_free(cursor); Bip_Error(Error_Code(res)); } cursor_field_value(cursor, rows_processed_count, (void **)&prows); rows = *prows; cursor_free(cursor); Return_Unify_Integer(v_rows, t_rows, rows); }
static int p_unlock2(value v, type t, value vl, type tl) { module_item *m; Check_Atom_Or_Nil(v, t); Check_String(tl); if (!IsModule(v.did)) { Bip_Error(MODULENAME); } if (!IsLocked(v.did)) { Succeed_; } if (DidModule(v.did) == HARD_LOCK_MODULE) { Bip_Error(LOCKED); } m = ModuleItem(v.did); if (!strcmp(m->lock, StringStart(vl))) { hg_free((generic_ptr) m->lock); DidModule(v.did) = UNLOCK_MODULE; m->lock = (char *) 0; Succeed_; } else { Bip_Error(WRONG_UNLOCK_STRING); } }
static int p_lock_pass_(value vl, type tl, value v, type t) { module_item *m; Check_Module_And_Access(v, t); Check_String(tl); DidModule(v.did) = SOFT_LOCK_MODULE; m = ModuleItem(v.did); /* the string should be stored crypted */ m->lock = (char *) hg_alloc((int) StringLength(vl) + 1); Copy_Bytes(m->lock, StringStart(vl), StringLength(vl) + 1); Succeed_; }
static int p_substring(value val1, type tag1, value val2, type tag2, value valp, type tagp) { char *p1, *p2; word length1, length2; word i, j; /* string1 and string2 must be strings; posn an integer/variable. */ Check_Output_Integer(tagp); Check_Output_String(tag1); Check_String(tag2); Error_If_Ref(tag1); length1 = StringLength(val1); length2 = StringLength(val2); if (!IsRef(tagp)) { if (valp.nint <= 0 || valp.nint > length1 + 1) { Bip_Error(RANGE_ERROR); } if (valp.nint > length1 - length2 + 1) { Fail_; /* string 2 is too long to match */ } p1 = StringStart(val1) + valp.nint - 1; p2 = StringStart(val2); for(j = 0; j < length2; ++j) { if (p1[j] != p2[j]) { Fail_; } } Succeed_; } else { p1 = StringStart(val1); p2 = StringStart(val2); for (i = 1; i <= length1 - length2 + 1; i++) { /* * search through p (i.e. string1) 'length2' characters * at a time for val2.str (i.e. string2), till the end * of string1. */ for(j = 0; j < length2; ++j) { if (p1[j] != p2[j]) break; } if (j == length2) { Return_Unify_Integer(valp, tagp, i); } p1++; } /* if not found, fail. */ Fail_; } }