Changeset 272 for trunk/src/shared/Database/SQLStorage.h
- Timestamp:
- 11/22/08 00:35:41 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shared/Database/SQLStorage.h
r260 r272 11 11 * This program is distributed in the hope that it will be useful, 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 15 * 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307USA18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 … … 27 27 class SQLStorage 28 28 { 29 template<class T>30 friend struct SQLStorageLoaderBase;31 32 29 public: 33 30 34 SQLStorage(const char* fmt, const char * _entry_field,const char * sqlname)31 SQLStorage(const char*fmt,const char * _entry_field,const char * sqlname) 35 32 { 36 src_format = fmt; 37 dst_format = fmt; 38 init(_entry_field, sqlname); 33 format=fmt; 34 entry_field = _entry_field; 35 table=sqlname; 36 data=NULL; 37 pIndex=NULL; 38 iNumFields =strlen(fmt); 39 MaxEntry = 0; 39 40 } 40 41 SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname)42 {43 src_format = src_fmt;44 dst_format = dst_fmt;45 init(_entry_field, sqlname);46 }47 48 49 41 ~SQLStorage() 50 42 { … … 65 57 uint32 MaxEntry; 66 58 uint32 iNumFields; 67 68 59 void Load(); 69 60 void Free(); 70 71 61 private: 72 void init(const char * _entry_field, const char * sqlname)73 {74 entry_field = _entry_field;75 table=sqlname;76 data=NULL;77 pIndex=NULL;78 iNumFields = strlen(src_format);79 MaxEntry = 0;80 }81 82 62 char** pIndex; 83 63 84 64 char *data; 85 const char *src_format; 86 const char *dst_format; 65 const char *format; 87 66 const char *table; 88 67 const char *entry_field; 89 68 //bool HasString; 90 69 }; 91 92 template <class T>93 struct SQLStorageLoaderBase94 {95 public:96 void Load(SQLStorage &storage);97 98 template<class S, class D>99 void convert(uint32 field_pos, S src, D &dst);100 template<class S>101 void convert_to_str(uint32 field_pos, S src, char * & dst);102 template<class D>103 void convert_from_str(uint32 field_pos, char * src, D& dst);104 void convert_str_to_str(uint32 field_pos, char *src, char *&dst);105 106 private:107 template<class V>108 void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset);109 void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset);110 };111 112 struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader>113 {114 };115 116 70 #endif