-
Notifications
You must be signed in to change notification settings - Fork 2
/
basesq.cpp
4904 lines (4367 loc) · 160 KB
/
basesq.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
// SELECT element FROM table ORDER BY name LIMIT OFFSET,NUMBER
#include "basesq.h"
#if defined(WITH_MYSQL)
#ifdef DEVELOPING_CSQL
///////////////////////////////////////////////////////////////////////////////
// SQL database definition.
USING_NAMESPACE(sq)
///////////////////////////////////////////////////////////////////////////
// Unique
Unique::Unique(void)
{ }
Unique::~Unique(void)
{ }
///////////////////////////////////////////////////////////////////////////
// Index
Index::Index(void)
{ }
Index::~Index(void)
{ }
///////////////////////////////////////////////////////////////////////////
// Reference
Reference::Reference(const basics::string<> &from, const basics::string<> &to, RefAction onDel, RefAction onUp, const basics::string<> &tbl)
: ref_from(from)
, ref_to(to)
, ref_onDel(onDel)
, ref_onUp(onUp)
, ref_tbl(tbl)
{ }
Reference::~Reference(void)
{
ref_from.clear();
ref_to.clear();
}
inline const RefAction& Reference::onDel(void) const
{
return ref_onDel;
}
inline const RefAction& Reference::onUp(void) const
{
return ref_onUp;
}
inline const basics::string<>& Reference::table(void) const
{
return ref_tbl;
}
///////////////////////////////////////////////////////////////////////////
// Property
template< typename T >
Property<T>::Property(void)
{ }
template< typename T >
Property<T>::Property(const basics::string<>& name, const basics::string<>& value)
: prop_name(name)
, prop_value(value)
{ }
template< typename T >
Property<T>::~Property(void)
{ }
template< typename T >
inline const basics::string<>& Property<T>::name(void)
{
return prop_name;
}
template< typename T >
inline const basics::string<>& Property<T>::value(void)
{
return prop_value;
}
///////////////////////////////////////////////////////////////////////////
// AutoIncrements
AutoIncrements::AutoIncrements(const uint32 from)
: inc_from(from)
{ }
AutoIncrements::~AutoIncrements(void)
{ }
inline const uint32 AutoIncrements::from(void) const
{
return inc_from;
}
///////////////////////////////////////////////////////////////////////////
// Default
Default::Default(const uint32 value)
: def_value()
{
def_value << value;
}
Default::Default(const basics::string<>& value)
: def_value(value)
{ }
Default::~Default(void)
{ }
inline const basics::string<>& Default::value(void) const
{
return def_value;
}
///////////////////////////////////////////////////////////////////////////
// Primary
Primary::Primary(void)
{ }
Primary::~Primary(void)
{ }
///////////////////////////////////////////////////////////////////////////
// Column
Column::Column(ColType type, const basics::string<>& name, bool null)
: col_type(type)
, col_name(name)
, col_null(null)
, col_hasDefault(false)
, col_default()
{ }
Column::~Column(void)
{ }
//##TODO continue adding the rest of the code
/*
//## can something like this be done? if so how?
template< typename TT extends Column >
Database& Database::operator<<(TT& col)
{
if( canAddColumn(col.name()) == true )
db_tbls.last() << col;
return *this;
}
*/
#endif
///////////////////////////////////////////////////////////////////////////////
// sql base interface.
// wrapper for the sql handle, table control and parameter storage
basics::CMySQL CSQLParameter::sqlbase;
basics::CParam< basics::string<> > CSQLParameter::mysqldb_id("sql_username", "ragnarok", &ParamCallback_Database_string);
basics::CParam< basics::string<> > CSQLParameter::mysqldb_pw("sql_password", "ragnarok", &ParamCallback_Database_string);
basics::CParam< basics::string<> > CSQLParameter::mysqldb_db("sql_database", "ragnarok", &ParamCallback_Database_string);
basics::CParam< basics::string<> > CSQLParameter::mysqldb_ip("sql_ip", "127.0.0.1", &ParamCallback_Database_string);
basics::CParam< basics::string<> > CSQLParameter::mysqldb_cp("sql_codepage", "DEFAULT", &ParamCallback_Database_string);
basics::CParam< ushort > CSQLParameter::mysqldb_port("sql_port", 3306, &ParamCallback_Database_ushort);
basics::CParam< basics::string<> > CSQLParameter::tbl_login_log("tbl_login_log", "login_log", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_char_log("tbl_char_log", "char_log", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_map_log("tbl_map_log", "map_log", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_login_status("tbl_login_status", "login_status", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_char_status("tbl_char_status", "char_status", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_map_status("tbl_map_status", "map_status", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_account("tbl_account", "account", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_char("tbl_char", "character", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_memo("tbl_memo", "memo", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_inventory("tbl_inventory", "inventory", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_cart("tbl_cart", "cart", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_skill("tbl_skill", "skill", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_friends("tbl_friends", "friends", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_mail("tbl_mail", "mail", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_login_reg("tbl_login_reg", "login_reg", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_login_reg2("tbl_login_reg2", "login_reg2", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_char_reg("tbl_char_reg", "char_reg", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild("tbl_guild","guild", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild_skill("tbl_guild_skill","guild_skill", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild_member("tbl_guild_member","guild_member", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild_position("tbl_guild_position","guild_position", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild_alliance("tbl_guild_alliance","guild_alliance", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild_expulsion("tbl_guild_expulsion","guild_expulsion", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_castle("tbl_castle","castle", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_castle_guardian("tbl_castle_guardian", "castle_guardian", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_party ("tbl_party", "party", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_storage("tbl_storage", "storage", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_guild_storage("tbl_guild_storage", "guild_storage", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_pet("tbl_pet", "pet", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_homunculus("tbl_homunculus", "homunculus", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_homunskill("tbl_homunskill", "homunskill", ParamCallback_Tables);
basics::CParam< basics::string<> > CSQLParameter::tbl_variable("tbl_variable", "variable", ParamCallback_Tables);
basics::CParam<bool> CSQLParameter::wipe_sql("wipe_sql", false);
basics::CParam< basics::string<> > CSQLParameter::sql_engine("sql_engine", "InnoDB"); // or "MyISAM"
basics::CParam<bool> CSQLParameter::log_login("log_login", true);
basics::CParam<bool> CSQLParameter::log_char("log_char", true);
basics::CParam<bool> CSQLParameter::log_map("log_map", true);
bool CSQLParameter::ParamCallback_Database_string(const basics::string<>& name, basics::string<>& newval, const basics::string<>& oldval)
{
sqlbase.init(mysqldb_id, mysqldb_pw,mysqldb_db,mysqldb_ip,mysqldb_port, mysqldb_cp);
return true;
}
bool CSQLParameter::ParamCallback_Database_ushort(const basics::string<>& name, ushort& newval, const ushort& oldval)
{
sqlbase.init(mysqldb_id, mysqldb_pw,mysqldb_db,mysqldb_ip,mysqldb_port, mysqldb_cp);
return true;
}
bool CSQLParameter::ParamCallback_Tables(const basics::string<>& name, basics::string<>& newval, const basics::string<>& oldval)
{
CSQLParameter::rebuild();
return true;
}
void CSQLParameter::rebuild()
{
// from mysql manual:
// restrictions on InnoDB:
//
// * `InnoDB' does not support the `AUTO_INCREMENT' table option for
// setting the initial sequence value in a `CREATE TABLE' or `ALTER
// TABLE' statement. To set the value with `InnoDB', insert a dummy
// row with a value one less and delete that dummy row, or insert the
// first row with an explicit value specified.
//
// foreign key issues:
//
// * If `ON DELETE' is the only referential integrity capability an
// application needs, note that as of MySQL Server 4.0, you can use
// multiple-table `DELETE' statements to delete rows from many tables
// with a single statement. *Note `DELETE': DELETE.
//
// * A workaround for the lack of `ON DELETE' is to add the appropriate
// `DELETE' statement to your application when you delete records
// from a table that has a foreign key. In practice, this is often as
// quick as using foreign keys, and is more portable.
// * Foreign key support addresses many referential integrity issues,
// but it is still necessary to design key relationships carefully to
// avoid circular rules or incorrect combinations of cascading
// deletes.
//
// * It is not uncommon for a DBA to create a topology of relationships
// that makes it difficult to restore individual tables from a backup.
// (MySQL alleviates this difficulty by allowing you to temporarily
// disable foreign key checks when reloading a table that depends on
// other tables. *Note InnoDB foreign key constraints::.
//
//
// * `INSERT DELAYED' works only with `MyISAM' and `ISAM' tables. For
// `MyISAM' tables, if there are no free blocks in the middle of the
// data file, concurrent `SELECT' and `INSERT' statements are
// supported. Under these circumstances, you very seldom need to use
// `INSERT DELAYED' with `MyISAM'. *Note `MyISAM' storage engine:
// MyISAM storage engine.
basics::slist< basics::string<> > existing_tables;
basics::CMySQLConnection dbcon1(CSQLParameter::sqlbase);
basics::string<> query;
#ifdef DEVELOPING_CSQL
sq::Database athena;
#endif
///////////////////////////////////////////////////////////////////////
// disable foreign keys
query << "SET FOREIGN_KEY_CHECKS=0";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////////
// drop all tables, drop child tables first
if( CSQLParameter::wipe_sql )
{
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_variable) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_homunskill) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_homunculus) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_pet) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_party) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_castle_guardian) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_castle) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild_expulsion) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild_alliance) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild_position) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild_skill) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild_member) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild_storage) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_storage) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_mail) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_skill) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_memo) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_cart) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_inventory) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_friends) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_char_reg) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_char) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_reg2) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_reg) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_account) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_status) << "`";
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////
query << "DROP TABLE IF EXISTS `"
<< dbcon1.escaped(CSQLParameter::tbl_login_log) << "`";
dbcon1.PureQuery(query);
query.clear();
}
else
{ // get a list of all tables
query << "SHOW TABLES";
if( dbcon1.ResultQuery(query) )
{
for(; dbcon1; ++dbcon1)
{
existing_tables.insert(dbcon1[0]);
}
}
query.clear();
}
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_log) << "` "
"("
"`time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,"
"`ip` VARCHAR(16) NOT NULL,"
"`user` VARCHAR(24) NOT NULL,"
"`rcode` INTEGER(3) UNSIGNED NOT NULL,"
"`log` VARCHAR(100) NOT NULL"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_login_log, CSQLParameter::sql_engine)
<< sq::Column(sq::TIMESTAMP,"time") << sq::Default("CURRENT_TIMESTAMP")
<< sq::TextColumn("ip",16,true,false)
<< sq::TextColumn("user",24,true,false)
<< sq::IntColumn<>("rcode",3,false)
<< sq::TextColumn("log",100,true,false);
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_status) << "` "
"("
"`index` INTEGER UNSIGNED NOT NULL,"
"`name` VARCHAR(24) NOT NULL,"
"`user` INTEGER UNSIGNED NOT NULL,"
"PRIMARY KEY(`index`)"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_login_status, CSQLParameter::sql_engine)
<< sq::IntColumn<>("index") << sq::Primary()
<< sq::TextColumn("name",24,true,false)
<< sq::IntColumn<>("user",false);
#endif
///////////////////////////////////////////////////////////////////////////
basics::CParam<uint32> start_account_num("start_account_num", 10000000);
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` "
"("
"`account_id` INTEGER UNSIGNED AUTO_INCREMENT,"
"`user_id` VARCHAR(24) NOT NULL,"
"`user_pass` VARCHAR(34) NOT NULL,"
"`sex` ENUM('M','F','S') default 'M',"
"`gm_level` INT(3) UNSIGNED NOT NULL default '0',"
"`online` BOOL default '0',"
"`email` VARCHAR(40) NOT NULL default 'a@a.com',"
"`login_id1` INTEGER UNSIGNED NOT NULL default '0',"
"`login_id2` INTEGER UNSIGNED NOT NULL default '0',"
"`client_ip` VARCHAR(16) NOT NULL default '',"
"`last_login` VARCHAR(24) NOT NULL default '',"
"`login_count` INTEGER UNSIGNED NOT NULL default '0',"
"`ban_until` INTEGER UNSIGNED NOT NULL default '0',"
"`valid_until` INTEGER UNSIGNED NOT NULL default '0',"
"PRIMARY KEY (`account_id`),"
"KEY `user_id` (`user_id`)"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine) << " AUTO_INCREMENT=" << start_account_num;
dbcon1.PureQuery(query);
query.clear();
query << "SET FOREIGN_KEY_CHECKS=0";
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
basics::string<> tbl_account(CSQLParameter::tbl_account);
athena << sq::Table(tbl_account, CSQLParameter::sql_engine)
<< sq::IntColumn<>("account_id") << sq::AutoIncrements(start_account_num) << sq::Primary()
<< sq::TextColumn("user_id",24,true,false) << sq::Index()
<< sq::TextColumn("user_pass",34,true,false)
<< sq::EnumColumn("sex","M","F","S") << sq::Default("M")
<< sq::IntColumn<>("gm_level",3,false) << sq::Default(0)
<< sq::BitColumn("online",1) << sq::Default(0)
<< sq::TextColumn("email",40,true,false) << sq::Default("a@a.com")
<< sq::IntColumn<>("login_id1",false) << sq::Default(0)
<< sq::IntColumn<>("login_id2",false) << sq::Default(0)
<< sq::TextColumn("client_ip",16,true,false) << sq::Default("")
<< sq::TextColumn("last_login",24,true,false) << sq::Default("")
<< sq::IntColumn<>("login_count",false) << sq::Default(0)
<< sq::IntColumn<>("ban_until",false) << sq::Default(0)
<< sq::IntColumn<>("valid_until",false) << sq::Default(0);
#endif
query << "INSERT INTO `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` "
"(`account_id`, `user_id`,`user_pass`) "
"VALUES "
"('" << start_account_num << "',' ',' ')";
dbcon1.PureQuery(query);
query.clear();
query << "DELETE FROM `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` "
"WHERE `account_id`=" << start_account_num;
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////////
// add the default accounts
//## change to inserting data from the config file
if( CSQLParameter::wipe_sql() || !existing_tables.find(CSQLParameter::tbl_account) )
{
query << "INSERT INTO `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` "
"(`user_id`,`user_pass`,`sex`) VALUES ('s1','p1','S'),('s2','p2','S'),('s3','p3','S')";
dbcon1.PureQuery(query);
query.clear();
ShowInfo("created default server accounts\n"CL_SPACE"it is recommended to modify the passwords\n");
}
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_reg) << "` "
"("
"`account_id` INTEGER UNSIGNED NOT NULL,"
"`str` VARCHAR(34) NOT NULL,"
"`value` VARCHAR(255) NOT NULL default '',"
"PRIMARY KEY (`account_id`,`str`),"
"KEY `account_id` (`account_id`),"
"FOREIGN KEY (`account_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_login_reg, CSQLParameter::sql_engine)
<< sq::RefColumn("account_id", sq::ACTION_CASCADE, sq::ACTION_CASCADE, tbl_account) << sq::Primary()
<< sq::TextColumn("str",34,true,false) << sq::Primary()
<< sq::TextColumn("value",255,true,false) << sq::Default("");
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_login_reg2) << "` "
"("
"`account_id` INTEGER UNSIGNED NOT NULL,"
"`str` VARCHAR(34) NOT NULL,"
"`value` VARCHAR(255) NOT NULL default '',"
"PRIMARY KEY (`account_id`,`str`),"
"KEY `account_id` (`account_id`),"
"FOREIGN KEY (`account_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::CopyTable(CSQLParameter::tbl_login_reg2,CSQLParameter::tbl_login_reg);
/*
athena << sq::Table(CSQLParameter::tbl_login_reg2, CSQLParameter::sql_engine)
<< sq::RefColumn("account_id", sq::ACTION_CASCADE, sq::ACTION_CASCADE, tbl_account) << sq::Primary()
<< sq::TextColumn("str",34,true) << sq::Primary()
<< sq::TextColumn("value",255,true,false) << sq::Default("");
*/
#endif
///////////////////////////////////////////////////////////////////////////
basics::CParam<uint32> start_char_num("start_char_num", 20000000);
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` "
"("
"`char_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,"
"`account_id` INTEGER UNSIGNED NOT NULL default '0',"
"`slot` TINYINT UNSIGNED NOT NULL default '0',"
"`name` VARCHAR(24) NOT NULL default '',"
"`class` SMALLINT UNSIGNED NOT NULL default '0',"
"`base_level` SMALLINT UNSIGNED NOT NULL default '1',"
"`job_level` SMALLINT UNSIGNED NOT NULL default '1',"
"`base_exp` BIGINT UNSIGNED NOT NULL default '0',"
"`job_exp` BIGINT UNSIGNED NOT NULL default '0',"
"`zeny` BIGINT UNSIGNED NOT NULL default '0',"
"`str` SMALLINT UNSIGNED NOT NULL default '0',"
"`agi` SMALLINT UNSIGNED NOT NULL default '0',"
"`vit` SMALLINT UNSIGNED NOT NULL default '0',"
"`int` SMALLINT UNSIGNED NOT NULL default '0',"
"`dex` SMALLINT UNSIGNED NOT NULL default '0',"
"`luk` SMALLINT UNSIGNED NOT NULL default '0',"
"`max_hp` INTEGER UNSIGNED NOT NULL default '0',"
"`hp` INTEGER UNSIGNED NOT NULL default '0',"
"`max_sp` INTEGER UNSIGNED NOT NULL default '0',"
"`sp` INTEGER UNSIGNED NOT NULL default '0',"
"`status_point` SMALLINT UNSIGNED NOT NULL default '0',"
"`skill_point` SMALLINT UNSIGNED NOT NULL default '0',"
"`option` SMALLINT NOT NULL default '0',"
"`karma` TINYINT NOT NULL default '0',"
"`chaos` TINYINT NOT NULL default '0',"
"`manner` SMALLINT NOT NULL default '0',"
"`party_id` INTEGER UNSIGNED NOT NULL default '0',"
"`guild_id` INTEGER UNSIGNED NOT NULL default '0',"
"`pet_id` INTEGER UNSIGNED NOT NULL default '0',"
"`hair` SMALLINT UNSIGNED NOT NULL default '0',"
"`hair_color` SMALLINT UNSIGNED NOT NULL default '0',"
"`clothes_color` SMALLINT UNSIGNED NOT NULL default '0',"
"`weapon` SMALLINT UNSIGNED NOT NULL default '1',"
"`shield` SMALLINT UNSIGNED NOT NULL default '0',"
"`head_top` SMALLINT UNSIGNED NOT NULL default '0',"
"`head_mid` SMALLINT UNSIGNED NOT NULL default '0',"
"`head_bottom` SMALLINT UNSIGNED NOT NULL default '0',"
"`last_map` VARCHAR(20) NOT NULL default 'new_5-1',"
"`last_x` SMALLINT UNSIGNED NOT NULL default '53',"
"`last_y` SMALLINT UNSIGNED NOT NULL default '111',"
"`save_map` VARCHAR(20) NOT NULL default 'new_5-1',"
"`save_x` SMALLINT UNSIGNED NOT NULL default '53',"
"`save_y` SMALLINT UNSIGNED NOT NULL default '111',"
"`partner_id` INTEGER UNSIGNED NOT NULL default '0',"
"`father_id` INTEGER UNSIGNED NOT NULL default '0',"
"`mother_id` INTEGER UNSIGNED NOT NULL default '0',"
"`child_id` INTEGER UNSIGNED NOT NULL default '0',"
"`fame_points` INTEGER UNSIGNED NOT NULL default '0',"
"`online` BOOL NOT NULL default '0',"
"PRIMARY KEY (`char_id`),"
"KEY `account_id` (`account_id`),"
"KEY `name` (`name`),"
"KEY `party_id` (`party_id`),"
"KEY `guild_id` (`guild_id`),"
"FOREIGN KEY (`account_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine) << " AUTO_INCREMENT=" << start_char_num;
dbcon1.PureQuery(query);
query.clear();
query << "SET FOREIGN_KEY_CHECKS=0";
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
basics::string<> tbl_char(CSQLParameter::tbl_char);
athena << sq::Table(tbl_char, CSQLParameter::sql_engine)
<< sq::IntColumn<>("char_id") << sq::AutoIncrements(start_account_num) << sq::Primary()
<< sq::RefColumn("account_id", sq::ACTION_CASCADE, sq::ACTION_CASCADE, tbl_account) << sq::Default(0)
<< sq::IntColumn<uint8>("slot",false) << sq::Default(0)
<< sq::TextColumn("name",24,true,false) << sq::Default("")
<< sq::IntColumn<uint16>("class",false) << sq::Default(0)
<< sq::IntColumn<uint16>("base_level",false) << sq::Default(1)
<< sq::IntColumn<uint16>("job_level",false) << sq::Default(1)
<< sq::IntColumn<uint64>("base_exp",false) << sq::Default(0)
<< sq::IntColumn<uint64>("job_exp",false) << sq::Default(0)
<< sq::IntColumn<uint64>("zeny",false) << sq::Default(0)
<< sq::IntColumn<uint16>("str",false) << sq::Default(0)
<< sq::IntColumn<uint16>("agi",false) << sq::Default(0)
<< sq::IntColumn<uint16>("vit",false) << sq::Default(0)
<< sq::IntColumn<uint16>("int",false) << sq::Default(0)
<< sq::IntColumn<uint16>("dex",false) << sq::Default(0)
<< sq::IntColumn<uint16>("luk",false) << sq::Default(0)
<< sq::IntColumn<>("max_hp",false) << sq::Default(0)
<< sq::IntColumn<>("hp",false) << sq::Default(0)
<< sq::IntColumn<>("max_sp",false) << sq::Default(0)
<< sq::IntColumn<>("sp",false) << sq::Default(0)
<< sq::IntColumn<uint16>("status_point",false) << sq::Default(0)
<< sq::IntColumn<uint16>("skill_point",false) << sq::Default(0)
<< sq::IntColumn<int16>("option",false) << sq::Default(0)
<< sq::IntColumn<uint8>("karma",false) << sq::Default(0)
<< sq::IntColumn<uint8>("chaos",false) << sq::Default(0)
<< sq::IntColumn<int16>("manner",false) << sq::Default(0)
<< sq::IntColumn<>("party_id",false) << sq::Default(0) << sq::Index()
<< sq::IntColumn<>("guild_id",false) << sq::Default(0) << sq::Index()
<< sq::IntColumn<>("pet_id",false) << sq::Default(0)
<< sq::IntColumn<uint16>("hair",false) << sq::Default(0)
<< sq::IntColumn<uint16>("hair_color",false) << sq::Default(0)
<< sq::IntColumn<uint16>("clothes_color",false) << sq::Default(0)
<< sq::IntColumn<uint16>("weapon",false) << sq::Default(0)
<< sq::IntColumn<uint16>("shield",false) << sq::Default(0)
<< sq::IntColumn<uint16>("head_top",false) << sq::Default(0)
<< sq::IntColumn<uint16>("head_mid",false) << sq::Default(0)
<< sq::IntColumn<uint16>("head_bottom",false) << sq::Default(0)
<< sq::TextColumn("last_map",20,true,false) << sq::Default("new_5-1")
<< sq::IntColumn<uint16>("last_x",false) << sq::Default(53)
<< sq::IntColumn<uint16>("last_y",false) << sq::Default(111)
<< sq::TextColumn("save_map",20,true,false) << sq::Default("new_5-1")
<< sq::IntColumn<uint16>("save_x",false) << sq::Default(53)
<< sq::IntColumn<uint16>("save_y",false) << sq::Default(111)
<< sq::IntColumn<>("partner_id",false) << sq::Default(0)
<< sq::IntColumn<>("mother_id",false) << sq::Default(0)
<< sq::IntColumn<>("child_id",false) << sq::Default(0)
<< sq::IntColumn<>("fame_points",false) << sq::Default(0)
<< sq::BitColumn("online",1) << sq::Default(0);
#endif
query << "INSERT INTO `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` "
"(`char_id`) "
"VALUES "
"('" << start_char_num << "')";
dbcon1.PureQuery(query);
query.clear();
query << "DELETE FROM `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` "
"WHERE `char_id`=" << start_char_num;
dbcon1.PureQuery(query);
query.clear();
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_char_reg) << "` "
"("
"`char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`str` VARCHAR(32) NOT NULL,"
"`value` VARCHAR(255) NOT NULL default '',"
"PRIMARY KEY (`char_id`,`str`),"
"KEY `char_id` (`char_id`),"
"FOREIGN KEY (`char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_char_reg, CSQLParameter::sql_engine)
<< sq::RefColumn("char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Primary()
<< sq::TextColumn("str",32,true,false) << sq::Primary()
<< sq::TextColumn("value",255,true,false) << sq::Default("");
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_friends) << "` ("
"`char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`friend_id` INTEGER UNSIGNED NOT NULL default '0',"
"PRIMARY KEY (`char_id`,`friend_id`),"
"KEY `char_id` (`char_id`),"
"KEY `friend_id` (`friend_id`),"
"FOREIGN KEY (`char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE,"
"FOREIGN KEY (`friend_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_friends, CSQLParameter::sql_engine)
<< sq::RefColumn("char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0) << sq::Primary()
<< sq::RefColumn("friend_id","char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0) << sq::Primary();
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_inventory) << "` ("
"`char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`nameid` SMALLINT UNSIGNED NOT NULL default '0',"
"`equip` SMALLINT UNSIGNED NOT NULL default '0',"
"`amount` INTEGER UNSIGNED NOT NULL default '0',"
"`refine` TINYINT(2) UNSIGNED NOT NULL default '0',"
"`attribute` TINYINT UNSIGNED NOT NULL default '0',"
"`identify` TINYINT UNSIGNED NOT NULL default '1',"
"`card0` SMALLINT UNSIGNED NOT NULL default '0',"
"`card1` SMALLINT UNSIGNED NOT NULL default '0',"
"`card2` SMALLINT UNSIGNED NOT NULL default '0',"
"`card3` SMALLINT UNSIGNED NOT NULL default '0',"
"KEY `char_id` (`char_id`),"
"FOREIGN KEY (`char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_inventory, CSQLParameter::sql_engine)
<< sq::RefColumn("char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0) << sq::Primary()
<< sq::IntColumn<uint16>("nameid",false) << sq::Default(0)
<< sq::IntColumn<uint16>("equip",false) << sq::Default(0)
<< sq::IntColumn<uint16>("amount",false) << sq::Default(0)
<< sq::IntColumn<uint8>("refine",2,false) << sq::Default(0)
<< sq::IntColumn<uint8>("attribute",false) << sq::Default(0)
<< sq::IntColumn<uint8>("identify",false) << sq::Default(1)
<< sq::IntColumn<uint16>("card0",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card1",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card2",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card3",false) << sq::Default(0);
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_cart) << "` ("
"`char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`nameid` SMALLINT UNSIGNED NOT NULL default '0',"
"`equip` SMALLINT UNSIGNED NOT NULL default '0',"
"`amount` INTEGER UNSIGNED NOT NULL default '0',"
"`refine` TINYINT(2) UNSIGNED NOT NULL default '0',"
"`attribute` TINYINT UNSIGNED NOT NULL default '0',"
"`identify` TINYINT UNSIGNED NOT NULL default '1',"
"`card0` SMALLINT UNSIGNED NOT NULL default '0',"
"`card1` SMALLINT UNSIGNED NOT NULL default '0',"
"`card2` SMALLINT UNSIGNED NOT NULL default '0',"
"`card3` SMALLINT UNSIGNED NOT NULL default '0',"
"KEY `char_id` (`char_id`),"
"FOREIGN KEY (`char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
/*
athena << sq::CopyTable(CSQLParameter::tbl_cart, CSQLParameter::tbl_inventory);
*/
athena << sq::Table(CSQLParameter::tbl_cart, CSQLParameter::sql_engine)
<< sq::RefColumn("char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0)
<< sq::IntColumn<uint16>("nameid",false) << sq::Default(0)
<< sq::IntColumn<uint16>("equip",false) << sq::Default(0)
<< sq::IntColumn<uint16>("amount",false) << sq::Default(0)
<< sq::IntColumn<uint8>("refine",2,false) << sq::Default(0)
<< sq::IntColumn<uint8>("attribute",false) << sq::Default(0)
<< sq::IntColumn<uint8>("identify",false) << sq::Default(1)
<< sq::IntColumn<uint16>("card0",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card1",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card2",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card3",false) << sq::Default(0);
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_memo) << "` ("
"`char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`map` VARCHAR(20) NOT NULL default '',"
"`x` SMALLINT UNSIGNED NOT NULL default '0',"
"`y` SMALLINT UNSIGNED NOT NULL default '0',"
"KEY `char_id` (`char_id`),"
"FOREIGN KEY (`char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_memo, CSQLParameter::sql_engine)
<< sq::RefColumn("char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0)
<< sq::TextColumn("map",20,true,false) << sq::Default("")
<< sq::IntColumn<uint16>("x",false) << sq::Default(0)
<< sq::IntColumn<uint16>("y",false) << sq::Default(0);
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_skill) << "` ("
"`char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`id` SMALLINT UNSIGNED NOT NULL default '0',"
"`lv` SMALLINT UNSIGNED NOT NULL default '0',"
"PRIMARY KEY (`char_id`,`id`),"
"KEY `char_id` (`char_id`),"
"FOREIGN KEY (`char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_skill, CSQLParameter::sql_engine)
<< sq::RefColumn("char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0) << sq::Primary()
<< sq::IntColumn<uint16>("id",false) << sq::Default(0) << sq::Primary()
<< sq::IntColumn<uint16>("lv",false) << sq::Default(0) << sq::Primary();
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_mail) << "` ("
"`message_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,"
"`to_char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`to_char_name` VARCHAR(24) NOT NULL default '',"
"`from_char_id` INTEGER UNSIGNED NOT NULL default '0',"
"`from_char_name` VARCHAR(24) NOT NULL default '',"
"`header` VARCHAR(32) NOT NULL default '',"
"`message` VARCHAR(80) NOT NULL default '',"
"`read_flag` BOOL default '0',"
"`sendtime` INTEGER UNSIGNED NOT NULL default '0',"
"`zeny` INTEGER UNSIGNED NOT NULL default '0',"
"`item_nameid` SMALLINT UNSIGNED NOT NULL default '0',"
"`item_amount` INTEGER UNSIGNED NOT NULL default '0',"
"`item_equip` SMALLINT UNSIGNED NOT NULL default '0',"
"`item_identify` TINYINT UNSIGNED NOT NULL default '1',"
"`item_refine` TINYINT UNSIGNED NOT NULL default '0',"
"`item_attribute` TINYINT UNSIGNED NOT NULL default '0',"
"`item_card0` SMALLINT UNSIGNED NOT NULL default '0',"
"`item_card1` SMALLINT UNSIGNED NOT NULL default '0',"
"`item_card2` SMALLINT UNSIGNED NOT NULL default '0',"
"`item_card3` SMALLINT UNSIGNED NOT NULL default '0',"
"PRIMARY KEY (`message_id`),"
"KEY `to_char_id` (`to_char_id`),"
"FOREIGN KEY (`to_char_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_char) << "` (`char_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine) << " AUTO_INCREMENT=1";
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_mail, CSQLParameter::sql_engine)
<< sq::IntColumn<uint32>("message_id",false) << sq::AutoIncrements(1) << sq::Primary()
<< sq::RefColumn("to_char_id","char_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_char) << sq::Default(0)
<< sq::TextColumn("to_char_name",24,true,false) << sq::Default("")
<< sq::IntColumn<uint32>("from_char_id",false) << sq::Default(0)
<< sq::TextColumn("from_char_name",24,true,false) << sq::Default("")
<< sq::TextColumn("header",32,true,false) << sq::Default("")
<< sq::TextColumn("message",80,true,false) << sq::Default("")
<< sq::BitColumn("read_flag",1) << sq::Default(0)
<< sq::IntColumn<>("sendtime",false) << sq::Default(0)
<< sq::IntColumn<>("zeny",false) << sq::Default(0)
<< sq::IntColumn<uint16>("item_nameid",false) << sq::Default(0)
<< sq::IntColumn<>("item_amount",false) << sq::Default(0)
<< sq::IntColumn<uint16>("item_equip",false) << sq::Default(0)
<< sq::IntColumn<uint8>("item_identify",false) << sq::Default(1)
<< sq::IntColumn<uint8>("item_refine",false) << sq::Default(0)
<< sq::IntColumn<uint8>("item_attribute",false) << sq::Default(0)
<< sq::IntColumn<uint16>("item_card0",false) << sq::Default(0)
<< sq::IntColumn<uint16>("item_card1",false) << sq::Default(0)
<< sq::IntColumn<uint16>("item_card2",false) << sq::Default(0)
<< sq::IntColumn<uint16>("item_card3",false) << sq::Default(0);
#endif
///////////////////////////////////////////////////////////////////////////
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_storage) << "` "
"("
"`account_id` INTEGER UNSIGNED NOT NULL default '0',"
"`nameid` SMALLINT UNSIGNED NOT NULL default '0',"
"`equip` SMALLINT UNSIGNED NOT NULL default '0',"
"`amount` INTEGER UNSIGNED NOT NULL default '0',"
"`refine` TINYINT UNSIGNED NOT NULL default '0',"
"`attribute` TINYINT UNSIGNED NOT NULL default '0',"
"`identify` TINYINT UNSIGNED NOT NULL default '1',"
"`card0` SMALLINT UNSIGNED NOT NULL default '0',"
"`card1` SMALLINT UNSIGNED NOT NULL default '0',"
"`card2` SMALLINT UNSIGNED NOT NULL default '0',"
"`card3` SMALLINT UNSIGNED NOT NULL default '0',"
"KEY `account_id` (`account_id`),"
"FOREIGN KEY (`account_id`) REFERENCES `" << dbcon1.escaped(CSQLParameter::tbl_account) << "` (`account_id`) ON DELETE CASCADE ON UPDATE CASCADE"
") "
"ENGINE = " << dbcon1.escaped(CSQLParameter::sql_engine);
dbcon1.PureQuery(query);
query.clear();
#ifdef DEVELOPING_CSQL
athena << sq::Table(CSQLParameter::tbl_storage, CSQLParameter::sql_engine)
<< sq::RefColumn("account_id",sq::ACTION_CASCADE,sq::ACTION_CASCADE,tbl_account) << sq::Default(0)
<< sq::IntColumn<uint16>("nameid",false) << sq::Default(0)
<< sq::IntColumn<uint16>("equip",false) << sq::Default(0)
<< sq::IntColumn<>("amount",false) << sq::Default(0)
<< sq::IntColumn<uint8>("refine",2,false) << sq::Default(0)
<< sq::IntColumn<uint8>("attribute",false) << sq::Default(0)
<< sq::IntColumn<uint8>("identify",false) << sq::Default(1)
<< sq::IntColumn<uint16>("card0",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card1",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card2",false) << sq::Default(0)
<< sq::IntColumn<uint16>("card3",false) << sq::Default(0);
#endif
///////////////////////////////////////////////////////////////////////////
basics::CParam<uint32> start_guild_num("start_guild_num", 30000000);
query << "CREATE TABLE IF NOT EXISTS `" << dbcon1.escaped(CSQLParameter::tbl_guild) << "` "
"("
"`guild_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,"
"`guild_lv` SMALLINT UNSIGNED NOT NULL default '0',"
"`connect_member` SMALLINT UNSIGNED NOT NULL default '0',"
"`max_member` SMALLINT UNSIGNED NOT NULL default '0',"
"`average_lv` SMALLINT UNSIGNED NOT NULL default '0',"
"`exp` INTEGER UNSIGNED NOT NULL default '0',"
"`next_exp` INTEGER UNSIGNED NOT NULL default '0',"
"`skill_point` SMALLINT UNSIGNED NOT NULL default '0',"
"`name` VARCHAR(24) NOT NULL default '',"
"`master_id` INTEGER UNSIGNED NOT NULL default '0',"
"`mes1` VARCHAR(64) NOT NULL default '',"
"`mes2` VARCHAR(128) NOT NULL default '',"
"`emblem_id` INTEGER UNSIGNED NOT NULL default '0',"
"`emblem_len` SMALLINT UNSIGNED NOT NULL default '0',"
"`emblem_data` BLOB NOT NULL,"