aboutsummaryrefslogtreecommitdiff
path: root/src/shared/Database/SQLStorage.h
diff options
context:
space:
mode:
authormegamage <none@none>2008-11-20 16:16:57 -0600
committermegamage <none@none>2008-11-20 16:16:57 -0600
commit1e997b95cc89c615adf2acd27a5f6916b78e0ff3 (patch)
tree491c496b798daf9b20db6397ae3f0affb6fd3738 /src/shared/Database/SQLStorage.h
parent0b61584e1b19afb8dbef376a4e2903d8631bfc1d (diff)
Re-commit 262 due to EOL issues. (no difference from 262)
--HG-- branch : trunk
Diffstat (limited to 'src/shared/Database/SQLStorage.h')
-rw-r--r--src/shared/Database/SQLStorage.h68
1 files changed, 57 insertions, 11 deletions
diff --git a/src/shared/Database/SQLStorage.h b/src/shared/Database/SQLStorage.h
index 5131a73fe4d..2d154f4e1ca 100644
--- a/src/shared/Database/SQLStorage.h
+++ b/src/shared/Database/SQLStorage.h
@@ -10,12 +10,12 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SQLSTORAGE_H
@@ -26,18 +26,26 @@
class SQLStorage
{
+ template<class T>
+ friend struct SQLStorageLoaderBase;
+
public:
- SQLStorage(const char*fmt,const char * _entry_field,const char * sqlname)
+ SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname)
{
- format=fmt;
- entry_field = _entry_field;
- table=sqlname;
- data=NULL;
- pIndex=NULL;
- iNumFields =strlen(fmt);
- MaxEntry = 0;
+ src_format = fmt;
+ dst_format = fmt;
+ init(_entry_field, sqlname);
+ }
+
+ SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname)
+ {
+ src_format = src_fmt;
+ dst_format = dst_fmt;
+ init(_entry_field, sqlname);
}
+
+
~SQLStorage()
{
Free();
@@ -56,15 +64,53 @@ class SQLStorage
uint32 RecordCount;
uint32 MaxEntry;
uint32 iNumFields;
+
void Load();
void Free();
+
private:
+ void init(const char * _entry_field, const char * sqlname)
+ {
+ entry_field = _entry_field;
+ table=sqlname;
+ data=NULL;
+ pIndex=NULL;
+ iNumFields = strlen(src_format);
+ MaxEntry = 0;
+ }
+
char** pIndex;
char *data;
- const char *format;
+ const char *src_format;
+ const char *dst_format;
const char *table;
const char *entry_field;
//bool HasString;
};
+
+template <class T>
+struct SQLStorageLoaderBase
+{
+ public:
+ void Load(SQLStorage &storage);
+
+ template<class S, class D>
+ void convert(uint32 field_pos, S src, D &dst);
+ template<class S>
+ void convert_to_str(uint32 field_pos, S src, char * & dst);
+ template<class D>
+ void convert_from_str(uint32 field_pos, char * src, D& dst);
+ void convert_str_to_str(uint32 field_pos, char *src, char *&dst);
+
+ private:
+ template<class V>
+ void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset);
+ void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset);
+};
+
+struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader>
+{
+};
+
#endif