17 // SQLRequest is inherited from a basic Request object
18 // so that we can neatly pass information around the
26 std::string thisquery;
28 SQLRequest(int qt, long cid, std::string query)
30 this->SetQueryType(qt);
32 this->SetQuery(query);
35 void SetConnID(long id)
45 void SetQueryType(int t)
55 void SetQuery(std::string query)
60 std::string GetQuery()
66 // Upon completion, an SQLRequest returns an SQLResponse.
74 std::map<std::string,std::string> row;
77 void SetRow(std::map<std::string,std::string> r)
82 std::string GetField(std::string field)
84 std::map<std::string,std::string>::iterator iter = row.find(field);
85 if (iter == row.end()) return "";
94 void SetError(std::string err)
104 std::string GetError()
109 void SetCount(long c)
114 /* This will return a negative value of the SQL server is down */
124 SQLRequest* rowrequest;
127 SQLResult* rowresult;
135 bool MakeQueryGoNow(std::string qry)
137 // Insert Lack of More Original Name here.
138 Request queryrequest((char*)query, parent, SQLModule);
139 result = (SQLResult*)queryrequest.Send();
140 if (result->GetType() != SQL_ERROR)
142 // Query Is fine.. Prepare to get first row...
143 rowrequest = new SQLRequest(SQL_ROW,dbid,"");
144 rowquery = new Request((char*)rowrequest, parent, SQLModule);
147 // Query Failed. - Coder Fucked up! (Probably me too :/)
148 Srv->Log(DEBUG, " ============= SQL Error, Query And Error Follow. ============= ");
149 Srv->Log(DEBUG, "Query: "+ qry);
150 Srv->Log(DEBUG, "Error: "+ result->GetError());
151 Srv->Log(DEBUG, " ============================================================== ");
152 // Destroy Variables that were set..
161 SQLQuery(Server* S) : Srv(S)
165 SQLQuery(Module* a, unsigned long b, Server* S) : dbid(b), parent(a), Srv(S)
167 // Make a few useful variables..
168 SQLModule = Srv->FindModule("m_sql.so");
175 bool Query(std::string qry)
177 query = new SQLRequest(SQL_RESULT, dbid, qry);
178 return MakeQueryGoNow(qry);
181 bool QueryCount(std::string qry)
183 query = new SQLRequest(SQL_COUNT, dbid, qry);
184 return MakeQueryGoNow(qry);
189 rowresult = (SQLResult*)rowquery->Send();
190 if (rowresult->GetType() == SQL_ROW)
192 // We have got a row.. thats all for now.
195 // No Row, Error, or end. KILL CALLER! *BANG*
199 std::string GetField(std::string fname)
201 return rowresult->GetField(fname);
206 rowresult = (SQLResult*)rowquery->Send();
207 if (rowresult->GetType() == SQL_COUNT)
209 return rowresult->GetCount();
219 // Tell m_sql we are finished..
220 query->SetQueryType(SQL_DONE);
221 query->SetConnID(dbid);
222 Request donerequest((char*)query, parent, SQLModule);
225 // Do Some Clearing up.
228 // Null the variables, so they can be re-used without confusion..
235 static std::string Sanitise(const std::string& crap)
237 std::string temp = "";
238 for (unsigned int q = 0; q < crap.length(); q++)
244 else if (crap[q] == '"')
248 else if (crap[q] == '\\')