#line 1 "sample.d" #line 23 "sample.d" /* * $Id: sample.d,v 1.3 2004/01/28 13:53:57 dtynan Exp $ * * This stuff appears at the front of the C code file... * (new to v0.5) */ #include "sample.h" #include #include #include #include #include "dbow.h" /* * C/C++ prolog file - the following information was generated by * DBOW, the database object generator. Do not edit the contents * of this file but instead the source file from which it was * generated. Changes to this file will be lost. * * Source is "sample.d" * Template is "$Id: c.m4,v 1.12 2006/03/06 13:18:43 dtynan Exp $" */ #include "dbow.h" struct db_user * db_useralloc() { struct db_user *p; if ((p = (struct db_user *)malloc(sizeof(struct db_user))) == NULL) return(NULL); memset((char *)p, 0, sizeof(struct db_user)); return(p); } void db_userfree(struct db_user *p) { if (p->dbres != NULL) dbow_free_result(p->dbres); if (p->fname != NULL) free(p->fname); if (p->lname != NULL) free(p->lname); if (p->a1 != NULL) free(p->a1); if (p->a2 != NULL) free(p->a2); if (p->a3 != NULL) free(p->a3); if (p->city != NULL) free(p->city); if (p->state_county != NULL) free(p->state_county); if (p->postcode_zip != NULL) free(p->postcode_zip); if (p->contact_phone != NULL) free(p->contact_phone); if (p->handle != NULL) free(p->handle); if (p->password != NULL) free(p->password); free((char *)p); } struct db_user * db_runuserquery(dbow_conn *c, char *q) { if (dbow_query(c, q) < 0) return(NULL); return(db_findusernext(c, NULL)); } struct db_user * db_finduserfirst(dbow_conn *c) { return(db_runuserquery(c, "SELECT user_id ,fname,lname,a1,a2,a3,city,state_county,postcode_zip,country_id,contact_phone,handle,password FROM user")); } struct db_user * db_findusernext(dbow_conn *c, struct db_user *p) { char **row; if (p == NULL) { if ((p = db_useralloc()) == NULL) return(NULL); p->dbres = c->dbres; } if ((row = dbow_fetch_row(p->dbres)) == NULL) { db_userfree(p); return(NULL); } p->user_id = (row[0] == NULL) ? 0 : atoi(row[0]); if (p->fname != NULL) free(p->fname); p->fname = (row[1] == NULL) ? NULL : strdup(row[1]); if (p->lname != NULL) free(p->lname); p->lname = (row[2] == NULL) ? NULL : strdup(row[2]); if (p->a1 != NULL) free(p->a1); p->a1 = (row[3] == NULL) ? NULL : strdup(row[3]); if (p->a2 != NULL) free(p->a2); p->a2 = (row[4] == NULL) ? NULL : strdup(row[4]); if (p->a3 != NULL) free(p->a3); p->a3 = (row[5] == NULL) ? NULL : strdup(row[5]); if (p->city != NULL) free(p->city); p->city = (row[6] == NULL) ? NULL : strdup(row[6]); if (p->state_county != NULL) free(p->state_county); p->state_county = (row[7] == NULL) ? NULL : strdup(row[7]); if (p->postcode_zip != NULL) free(p->postcode_zip); p->postcode_zip = (row[8] == NULL) ? NULL : strdup(row[8]); p->country_id = (row[9] == NULL) ? 0 : atoi(row[9]); if (p->contact_phone != NULL) free(p->contact_phone); p->contact_phone = (row[10] == NULL) ? NULL : strdup(row[10]); if (p->handle != NULL) free(p->handle); p->handle = (row[11] == NULL) ? NULL : strdup(row[11]); if (p->password != NULL) free(p->password); p->password = (row[12] == NULL) ? NULL : strdup(row[12]); return(p); } int db_insertuser(dbow_conn *c, struct db_user *p) { if (dbow_query(c, "INSERT INTO user VALUES ($c ,$o,$o,$o,$o,$o,$o,$o,$o,$c,$o,$o,$o)", p->user_id ,p->fname,p->lname,p->a1,p->a2,p->a3,p->city,p->state_county,p->postcode_zip,p->country_id,p->contact_phone,p->handle,p->password) < 0) return(-1); if (p->user_id == 0) p->user_id = dbow_insertid(c); return(0); } int db_deleteuserbyuser_id(dbow_conn *c, int x) { if (dbow_query(c, "DELETE FROM user WHERE user_id = $c", x) < 0) return(-1); return(0); } struct db_user * db_finduserbyuser_id(dbow_conn *c, int x) { if (dbow_query(c, "SELECT user_id ,fname,lname,a1,a2,a3,city,state_county,postcode_zip,country_id,contact_phone,handle,password FROM user WHERE user_id = $c", x) < 0) return(NULL); return(db_findusernext(c, NULL)); } int db_updateuserbyuser_id(dbow_conn *c, struct db_user *p, int x) { if (dbow_query(c, "UPDATE user SET user_id = $c ,fname = $o,lname = $o,a1 = $o,a2 = $o,a3 = $o,city = $o,state_county = $o,postcode_zip = $o,country_id = $c,contact_phone = $o,handle = $o,password = $o WHERE user_id = $c", p->user_id, p->fname, p->lname, p->a1, p->a2, p->a3, p->city, p->state_county, p->postcode_zip, p->country_id, p->contact_phone, p->handle, p->password, x) < 0) return(-1); return(0); } #line 6 "sample.d" /* * $Id: sample.d,v 1.3 2004/01/28 13:53:57 dtynan Exp $ * * This stuff appears at the end of the code file. */