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;
76 void SetRow(std::map<std::string,std::string> r)
81 std::string GetField(std::string field)
83 std::map<std::string,std::string>::iterator iter = row.find(field);
84 if (iter == row.end()) return "";
93 void SetError(std::string err)
103 std::string GetError()
108 void SetCount(unsigned long c)
113 unsigned long GetCount()
122 SQLRequest* rowrequest;
125 SQLResult* rowresult;
133 bool MakeQueryGoNow(std::string qry)
135 // Insert Lack of More Original Name here.
136 Request queryrequest((char*)query, parent, SQLModule);
137 result = (SQLResult*)queryrequest.Send();
138 if (result->GetType() != SQL_ERROR)
140 // Query Is fine.. Prepare to get first row...
141 rowrequest = new SQLRequest(SQL_ROW,dbid,"");
142 rowquery = new Request((char*)rowrequest, parent, SQLModule);
145 // Query Failed. - Coder Fucked up! (Probably me too :/)
146 Srv->Log(DEBUG, " ============= SQL Error, Query And Error Follow. ============= ");
147 Srv->Log(DEBUG, "Query: "+ qry);
148 Srv->Log(DEBUG, "Error: "+ result->GetError());
149 Srv->Log(DEBUG, " ============================================================== ");
150 // Destroy Variables that were set..
159 SQLQuery(Server* S) : Srv(S)
163 SQLQuery(Module* a, unsigned long b, Server* S) : dbid(b), parent(a), Srv(S)
165 // Make a few useful variables..
166 SQLModule = Srv->FindModule("m_sql.so");
173 bool Query(std::string qry)
175 query = new SQLRequest(SQL_RESULT, dbid, qry);
176 return MakeQueryGoNow(qry);
179 bool QueryCount(std::string qry)
181 query = new SQLRequest(SQL_COUNT, dbid, qry);
182 return MakeQueryGoNow(qry);
187 rowresult = (SQLResult*)rowquery->Send();
188 if (rowresult->GetType() == SQL_ROW)
190 // We have got a row.. thats all for now.
193 // No Row, Error, or end. KILL CALLER! *BANG*
197 std::string GetField(std::string fname)
199 return rowresult->GetField(fname);
204 rowresult = (SQLResult*)rowquery->Send();
205 if (rowresult->GetType() == SQL_COUNT)
207 return rowresult->GetCount();
217 // Tell m_sql we are finished..
218 query->SetQueryType(SQL_DONE);
219 query->SetConnID(dbid);
220 Request donerequest((char*)query, parent, SQLModule);
223 // Do Some Clearing up.
226 // Null the variables, so they can be re-used without confusion..
233 std::string Sanitise(std::string crap)
235 std::string temp = "";
236 for (unsigned int q = 0; q < crap.length(); q++)
242 else if (crap[q] == '"')
244 temp = temp + "\\\"";
247 temp = temp + crap[q];