summaryrefslogtreecommitdiff
path: root/src/modules/extra/m_sqlv2.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/extra/m_sqlv2.h')
-rw-r--r--src/modules/extra/m_sqlv2.h77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/modules/extra/m_sqlv2.h b/src/modules/extra/m_sqlv2.h
index 1354e5dfc..d93e59b47 100644
--- a/src/modules/extra/m_sqlv2.h
+++ b/src/modules/extra/m_sqlv2.h
@@ -6,10 +6,22 @@
#define SQLSUCCESS "You shouldn't be reading this (success)"
#include <string>
+#include <vector>
+#include <map>
#include "modules.h"
enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL };
+class SQLexception
+{
+};
+
+class SQLbadColName : public SQLexception
+{
+public:
+ SQLbadColName() { }
+};
+
class SQLerror : public classbase
{
SQLerrorNum id;
@@ -72,6 +84,25 @@ public:
}
};
+class SQLfield
+{
+public:
+ /* The data itself */
+ std::string d;
+
+ /* If the field was null */
+ bool null;
+
+ SQLfield(const std::string &data, bool n)
+ : d(data), null(n)
+ {
+
+ }
+};
+
+typedef std::vector<SQLfield> SQLfieldList;
+typedef std::map<std::string, SQLfield> SQLfieldMap;
+
class SQLresult : public Request
{
public:
@@ -82,10 +113,54 @@ public:
SQLresult(Module* s, Module* d)
: Request(SQLRESID, s, d)
{
-
}
+ /* Return the number of rows in the result */
virtual int Rows() = 0;
+
+ /* Return the number of columns in the result */
+ virtual int Cols() = 0;
+
+ /* Get a string name of the column by an index number */
+ virtual std::string ColName(int column) = 0;
+
+ /* Get an index number for a column from a string name.
+ * An exception of type SQLbadColName will be thrown if
+ * the name given is invalid.
+ */
+ virtual int ColNum(const std::string &column) = 0;
+
+ /* Get a string value in a given row and column */
+ virtual SQLfield GetValue(int row, int column) = 0;
+
+ /* Return a list of values in a row, this should
+ * increment an internal counter so you can repeatedly
+ * call it until it returns an empty vector.
+ * This returns a reference to an internal object,
+ * the same object is used for all calls to this function
+ * and therefore the return value is only valid until
+ * you call this function again. It is also invalid if
+ * the SQLresult object is destroyed.
+ */
+ virtual SQLfieldList& GetRow() = 0;
+
+ /* As above, but return a map indexed by key name */
+ virtual SQLfieldMap& GetRowMap() = 0;
+
+ /* Like GetRow(), but returns a pointer to a dynamically
+ * allocated object which must be explicitly freed. For
+ * portability reasons this must be freed with SQLresult::Free()
+ */
+ virtual SQLfieldList* GetRowPtr() = 0;
+
+ /* As above, but return a map indexed by key name */
+ virtual SQLfieldMap* GetRowMapPtr() = 0;
+
+ /* Overloaded function for freeing the lists and maps returned
+ * above.
+ */
+ virtual void Free(SQLfieldMap* fm) = 0;
+ virtual void Free(SQLfieldList* fl) = 0;
};
#endif