#include <libsample.h>
Collaboration diagram for Sampletable:
Public Member Functions | |
Sampletable (Database *) | |
Sampletable (Database *, const std::string &) | |
Sampletable (Database *, Query *) | |
Sampletable (Database &, long num) | |
~Sampletable () | |
void | select (const std::string &) |
long | insert () |
void | update () |
void | save () |
void | erase () |
std::string | xml () |
std::string | xml (const std::string &, const std::string &) |
int | num_cols () |
Public Attributes | |
long | num |
std::string | name |
Private Member Functions | |
void | update (long num) |
void | clear () |
void | spawn (const std::string &) |
void | spawn (Query *) |
Private Attributes | |
Database * | database |
short | new_object |
Definition at line 37 of file libsample.h.
Sampletable::Sampletable | ( | Database * | db | ) |
Begin class 'Sampletable'
Definition at line 37 of file libsample.cpp.
References clear(), database, and new_object.
00038 { 00039 database = db; 00040 new_object = 1; 00041 clear(); 00042 }
Sampletable::Sampletable | ( | Database * | , | |
const std::string & | ||||
) |
Definition at line 43 of file libsample.cpp.
References database, new_object, and spawn().
00044 { 00045 database = db; 00046 new_object = 1; 00047 spawn(sql); 00048 }
Sampletable::Sampletable | ( | Database * | , | |
Query * | ||||
) |
Definition at line 49 of file libsample.cpp.
References database, new_object, and spawn().
00050 { 00051 database = db; 00052 new_object = 0; 00053 spawn(qd); 00054 }
Sampletable::Sampletable | ( | Database & | , | |
long | num | |||
) |
Definition at line 55 of file libsample.cpp.
References database, and spawn().
00055 : database(&db),new_object(1) 00056 { 00057 Query q(database); 00058 std::string sql = "select * from sampletable where "; 00059 { 00060 char slask[100]; 00061 sprintf(slask,"num='%ld'",i_num); 00062 sql += slask; 00063 } 00064 spawn(sql); 00065 }
Sampletable::~Sampletable | ( | ) |
void Sampletable::select | ( | const std::string & | ) |
long Sampletable::insert | ( | ) |
Definition at line 75 of file libsample.cpp.
References database, name, new_object, and num.
Referenced by save().
00076 { 00077 Query q(database); 00078 std::string sql; 00079 00080 sql = "insert into sampletable(num,name)"; 00081 { 00082 char slask[100]; 00083 sprintf(slask," values(%ld",this -> num); 00084 sql += slask; 00085 } 00086 sql += ", '" + q.safestr(this -> name) + "'"; 00087 sql += ")"; 00088 q.execute(sql); 00089 new_object = 0; 00090 return num = q.insert_id(); 00091 }
void Sampletable::update | ( | ) |
void Sampletable::save | ( | ) |
Definition at line 111 of file libsample.cpp.
References insert(), new_object, and update().
00112 { 00113 if (new_object) 00114 insert(); 00115 else 00116 update(); 00117 }
void Sampletable::erase | ( | ) |
Definition at line 119 of file libsample.cpp.
References database, new_object, and num.
00120 { 00121 if (!new_object) 00122 { 00123 std::string sql = "delete from sampletable where"; 00124 Query q(database); 00125 { 00126 char slask[200]; 00127 sprintf(slask," num='%ld'",this -> num); 00128 sql += slask; 00129 } 00130 q.execute(sql); 00131 } 00132 }
std::string Sampletable::xml | ( | ) |
Definition at line 134 of file libsample.cpp.
References database, name, and num.
00135 { 00136 Query q(database); 00137 std::string dest; 00138 char slask[200]; 00139 dest = "<SAMPLETABLE>"; 00140 sprintf(slask,"<NUM>%ld</NUM>",num); 00141 dest += slask; 00142 dest += "<NAME>" + q.xmlsafestr(name) + "</NAME>"; 00143 dest += "</SAMPLETABLE>"; 00144 return dest; 00145 }
std::string Sampletable::xml | ( | const std::string & | , | |
const std::string & | ||||
) |
Definition at line 147 of file libsample.cpp.
References database, name, and num.
00148 { 00149 Query q(database); 00150 std::string dest; 00151 char slask[200]; 00152 dest = "<SAMPLETABLE " + tag + "=\"" + xvalx + "\">"; 00153 sprintf(slask,"<NUM>%ld</NUM>",num); 00154 dest += slask; 00155 dest += "<NAME>" + q.xmlsafestr(name) + "</NAME>"; 00156 dest += "</SAMPLETABLE>"; 00157 return dest; 00158 }
int Sampletable::num_cols | ( | ) |
void Sampletable::update | ( | long | num | ) | [private] |
Definition at line 98 of file libsample.cpp.
References database, and name.
00099 { 00100 Query q(database); 00101 std::string sql; 00102 sql += "update sampletable set name='" + q.safestr(this -> name) + "'"; 00103 { 00104 char slask[200]; 00105 sprintf(slask," where num='%ld'",i_num); 00106 sql += slask; 00107 } 00108 q.execute(sql); 00109 }
void Sampletable::clear | ( | ) | [private] |
Definition at line 165 of file libsample.cpp.
References num.
Referenced by Sampletable(), and spawn().
00166 { 00167 num = 0; 00168 }
void Sampletable::spawn | ( | const std::string & | ) | [private] |
Definition at line 169 of file libsample.cpp.
References clear(), database, name, new_object, and num.
Referenced by Sampletable(), and select().
00170 { 00171 Query q(database); 00172 std::string temp; 00173 00174 if (!strncasecmp(sql.c_str(),"select * ",9)) 00175 { 00176 temp = "select num,name " + sql.substr(9); 00177 } else 00178 temp = sql; 00179 q.get_result(temp); 00180 if (q.fetch_row()) 00181 { 00182 num = q.getval(0); // 0 - num integer 00183 name = q.getstr(1); // 1 - name varchar(255) 00184 new_object = 0; 00185 } else 00186 clear(); 00187 q.free_result(); 00188 }
void Sampletable::spawn | ( | Query * | ) | [private] |
long Sampletable::num |
std::string Sampletable::name |
Database* Sampletable::database [private] |
Definition at line 62 of file libsample.h.
Referenced by erase(), insert(), Sampletable(), spawn(), update(), and xml().
short Sampletable::new_object [private] |
Definition at line 63 of file libsample.h.
Referenced by erase(), insert(), Sampletable(), save(), and spawn().