/* * This file is part of RuneOptimizer. * * RuneOptimizer is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * * RuneOptimizer 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 GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * RuneOptimizer. If not, see . */ /** * @file update_db_tables.c * * Implementation of {@link update_db_tables}. * * This file implements the funciton {@link update_db_tables} declared in * {@link update.h}. */ #include #include #include "../runeoptimizer.h" #include "../error/error.h" #include "../db/db.h" extern int update_db_tables(unsigned char clear_teams){ // Drop all tables char table_names[6][11] = { "rune_stats", "runes", "units", "info", "teams", "units_teams" }; char query_drop[64]; int tables_to_drop = 4; // By default, only drop the first 6 tables. If clear teams flag, all 6. if (clear_teams == TRUE){ tables_to_drop = 6; } for (int i = 0; i < tables_to_drop; i ++){ sprintf(query_drop, "DROP TABLE IF EXISTS %s;", table_names[i]); if (SUCCESS != db_execute(query_drop, NULL)){ fprintf( stderr, "Unable to drop table %s: %s\n", table_names[i], sqlite3_errmsg(db) ); return ERROR_DB_DROP; } } // Table rune_stats if ( SUCCESS != db_execute( "CREATE TABLE IF NOT EXISTS rune_stats(" " rune CHAR(12), slot INT, stat INT, value INT, grind INT, enchant INT" ");", NULL ) ){ fprintf( stderr, "Unable to create table rune_stats: %s\n", sqlite3_errmsg(db) ); return ERROR_DB_CREATE_RUNE_STATS; } // Table runes if ( SUCCESS != db_execute( "CREATE TABLE IF NOT EXISTS runes(" " id CHAR(12)," " unit CHAR(12)," " type INT," " slot INT," " stars INT," " level INT," " quality INT," " efficiency FLOAT," " max_efficiency FLOAT," " main_stat INT," " current_hp_percent INT," " current_atk_percent INT," " current_def_percent INT," " current_hp_flat INT," " current_atk_flat INT," " current_def_flat INT," " current_spd INT," " current_crr INT," " current_crd INT," " current_acc INT," " current_res INT," " lv12_hp_percent INT," " lv12_atk_percent INT," " lv12_def_percent INT," " lv12_hp_flat INT," " lv12_atk_flat INT," " lv12_def_flat INT," " lv12_spd INT," " lv12_crr INT," " lv12_crd INT," " lv12_acc INT," " lv12_res INT," " lv15_hp_percent INT," " lv15_atk_percent INT," " lv15_def_percent INT," " lv15_hp_flat INT," " lv15_atk_flat INT," " lv15_def_flat INT," " lv15_spd INT," " lv15_crr INT," " lv15_crd INT," " lv15_acc INT," " lv15_res INT" ");", NULL ) ){ fprintf( stderr, "Unable to create table runes: %s\n", sqlite3_errmsg(db) ); return ERROR_DB_CREATE_RUNES; } // Table units if ( SUCCESS != db_execute( "CREATE TABLE IF NOT EXISTS units(" " id CHAR(12)," " monster INT," " name CHAR(128)," " stars INT," " level INT," " storage INT," " base_hp INT," " base_atk INT," " base_def INT," " base_spd INT," " base_crr INT," " base_crd INT," " base_res INT," " base_acc INT," " current_hp INT," " current_atk INT," " current_def INT," " current_spd INT," " current_crr INT," " current_crd INT," " current_res INT," " current_acc INT" ");", NULL ) ){ fprintf( stderr, "Unable to create table units: %s\n", sqlite3_errmsg(db) ); return ERROR_DB_CREATE_UNITS; } // Table info if ( SUCCESS != db_execute( "CREATE TABLE IF NOT EXISTS info(" " player_id CHAR(12)," " player_name CHAR(64)," " player_level INT," " ts DATETIME," " modified INT" ");", NULL ) ){ fprintf( stderr, "Unable to create table info: %s\n", sqlite3_errmsg(db) ); return ERROR_DB_CREATE_INFO; } // Tables teams and units_teams (optional) if (clear_teams == TRUE){ if ( SUCCESS != db_execute( "CREATE TABLE IF NOT EXISTS " "units_teams(unit CHAR(12), team CHAR(12));", NULL ) ){ fprintf( stderr, "Unable to create table units_teams: %s\n", sqlite3_errmsg(db) ); return ERROR_DB_CREATE_UNITS_TEAMS; } if ( SUCCESS != db_execute( "CREATE TABLE IF NOT EXISTS " "teams(id CHAR(12), name CHAR(50), priority INT);", NULL ) ){ fprintf( stderr, "Unable to create table teams: %s\n", sqlite3_errmsg(db) ); return ERROR_DB_CREATE_TEAMS; } } return SUCCESS; }