www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Function and variable assignment

reply Jeremy Cowgar <jeremy __no__spAM__cowgar.com> writes:
I have the database api all setup and functioning, but now I would like 
to do something like:

Results res = db.query("SELECT * FROM people");
Row row;
char[] name, city, state, zip;

row.bind("name", name);
row.bind("city", city);
row.bind("state", state);
row.bind("zip", zip);

while((row = res.fetchRow()) != null) {
   printf("Name = %.*s, city = %.*s, state = %.*s, zip = %.*s", name, 
city, state, zip);
}


----

the row.bind function is what I do not know how to develop, or if it's 
even possible. Can someone give me a simple example? Not of how the 
database api works, but simply how I would store a reference to the char 
array for later assigning and repeat assigning in my Row class.

Thanks!

Jeremy
Apr 13 2005
parent Chris Sauls <ibisbasenji gmail.com> writes:
Hmm... maybe something like this:






Where Row.bind is defined as:


Then keep a map of variables locally, something like:


Just a 20-seconds-of-thought suggestion.

-- Chris Sauls

Jeremy Cowgar wrote:
 I have the database api all setup and functioning, but now I would like 
 to do something like:
 
 Results res = db.query("SELECT * FROM people");
 Row row;
 char[] name, city, state, zip;
 
 row.bind("name", name);
 row.bind("city", city);
 row.bind("state", state);
 row.bind("zip", zip);
 
 while((row = res.fetchRow()) != null) {
   printf("Name = %.*s, city = %.*s, state = %.*s, zip = %.*s", name, 
 city, state, zip);
 }
 
 
 ----
 
 the row.bind function is what I do not know how to develop, or if it's 
 even possible. Can someone give me a simple example? Not of how the 
 database api works, but simply how I would store a reference to the char 
 array for later assigning and repeat assigning in my Row class.
 
 Thanks!
 
 Jeremy
Apr 13 2005