.rdb zu .sql



  • Hallo,

    ich habe ein Problem:
    Ich kann nicht programmieren (habe nur ein bisschen Kenntnis von Delphi) und bin aber auf ein kleines Programm angewiesen, welches eine .rdb Datein ind eine .sql Datei umwandelt.

    Für das Programm gibt es einen Beispielcode, der auch funktioniert, aber ich muss ihn umwandeln für eine andere, ähnliche .rdb Datei.

    Folgende Codes funktionieren:
    http://pastebin.com/ZAqrkA0T
    http://pastebin.com/c9NTrarv

    die Dateien dazu : http://speedy.sh/eETHT/rdb-funktionieren.rar

    Für folgende Datei muss ich den umändern: http://speedy.sh/bfHWH/rdb-funktioniert-nicht.rar

    Das ist mein Code (der im CodeLite kein error produziert):

    //RDB TO SQL FOR db_monster TO dbo.MonsterResource
        //Date: 09.12.2012
        #include <iostream>
        #include <fstream>
        using namespace std;
    
        struct db_monster {
          int id;
    	  int monster_group;
    	  int name_id;
    	  int location_id;
    	  char model[256];
    	  int motion_file_id;
    	  int transform_level;
    	  int walk_type;
    	  int slant_type;
    	  float size;
    	  float scale;
    	  float target_fx_size;
    	  int camera_x;
    	  int camera_y;
    	  int camera_z;
    	  float target_x;
    	  float target_y;
    	  float target_z;
    	  int level;
    	  int grp;
    	  int magic_type;
    	  int race;
    	  int visible_range;
    	  int chase_range;
    	  int f_fisrt_attack;
    	  int f_group_first_attack;
    	  int f_response_casting;
    	  int f_response_race;
    	  int f_response_battle;
    	  int monster_type;
    	  int stat_id;
    	  int fight_type;
    	  int monster_skill_link_id;
    	  int material;
    	  int weapon_type;
    	  int attack_motion_speed;
    	  int ability;
    	  int standard_walk_spped;
    	  int standard_run_spped;
    	  int walk_speed;
    	  int run_speed;
    	  float attack_range;
    	  float hidesense_range;
    	  int hp;
    	  int mp;
    	  int attack_point;
    	  int magic_point;
    	  int defence;
    	  int magic_defence;
    	  int attack_speed;
    	  int magic_speed;
    	  int accuracy;
    	  int avoid;
    	  int magic_accuracy;
    	  int magic_avoid;
    	  int taming_id;
    	  float taming_percentage;
    	  float taming_exp_mod;
    	  int exp;
    	  int jp;
    	  int gold_drop_percentage;
    	  int gold_min;
    	  int gold_max;
    	  int chaos_drop_percentage;
    	  int chaos_min;
    	  int chaos_max;
    	  int exp_2;
    	  int jp_2;
    	  int gold_min_2;
    	  int gold_max_2;
    	  int chaos_min_2;
    	  int chaos_max_2;
    	  int drop_table_link_id;
    	  int texture_group;
    	  int local_flag;
    	  char script_on_dead[256];
    
        };
    
        int main()
        {
            int nbloop; //var for count number of loop
            ifstream RDB; //stream for read rdb
            ofstream SQL; //stream for write sql
            RDB.open("db_monster.rdb", ios::in | ios::binary); //open RDB file
    
            if(!RDB)//if the file can't be open
            {
                cout << "Kann die Datei nicht öffnen. Ist sie vielleicht nicht im selben Ordner wie MonsterResourceTOsql?\n";
                return 1;
            }
            SQL.open("db_monster.sql"); //open SQL file
            RDB.seekg(128, ios::beg); //We go over the header(128empty bit)
            RDB.read((char *) &nbloop,4);//we read 4bit(int) corresponding to the nb of line
    
            db_monster data[nbloop];//create array who will contening each information
            for(int i=0; i<nbloop; i++) //loop for read all data
            {
                RDB.read((char *) &data[i], sizeof(db_monster));//put each data from structure into
            }
    
            RDB.close(); //close RDB
    
            if(!RDB.good()) //If error durring reading(some time because you try to read more than you can)
            {
                cout << "Ein Fehler ist aufgetreten!\n";
                return 1;
            }
            //Wrinting Drop & create for CreatureFarmResource
             SQL << "USE [Arcadia]\nGO\n/****** Object:  Table [dbo].[MonsterResource]    Script Date: 09/12/2012 01:32:00 ******/\nDROP TABLE [dbo].[MonsterResource]\nGO\n\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nCREATE TABLE [dbo].[MonsterResource](\n [id] [int] NOT NULL, \n [monster_group] [int] NOT NULL, \n [name_id] [int] NOT NULL, \n [location_id] [int] NOT NULL, \n [model] [varchar(256)] NOT NULL, \n [motion_file_id] [int] NOT NULL, \n [transform_level] [int] NOT NULL, \n [walk_type] [tinyint] NOT NULL, \n [slant_type] [tinyint] NOT NULL, \n [size] [decimal(10,2)] NOT NULL, \n [scale] [decimal(10,2)] NOT NULL, \n [target_fx_szize] [decimal(10,2)] NOT NULL, \n [camera_x] [int] NOT NULL, \n [camera_y] [int] NOT NULL, \n [camera_z] [int] NOT NULL, \n [target_x] [decimal(10,2)] NOT NULL, \n [target_y] [decimal(10,2)] NOT NULL, \n [target_z] [decimal(10,2)] NOT NULL, \n [level] [int] NOT NULL, \n [grp] [int] NOT NULL, \n [magic_type] [int] NOT NULL, \n [race] [int] NOT NULL, \n [visible_range] [int] NOT NULL, \n [chase_range] [int] NOT NULL, \n [f_fisrt_attack] [tinyint] NOT NULL, \n [f_group_first_attack] [tinyint] NOT NULL, \n [f_response_casting] [tinyint] NOT NULL, \n [f_response_race] [tinyint] NOT NULL, \n [f_response_battle] [tinyint] NOT NULL, \n [monster_type] [tinyint] NOT NULL, \n [stat_id] [int] NOT NULL, \n [fight_type] [int] NOT NULL, \n [monster_skill_link_id] [int] NOT NULL, \n [material] [int] NOT NULL, \n [weapon_type] [int] NOT NULL, \n [attack_motion_speed] [int] NOT NULL, \n [ability] [int] NOT NULL, \n [standard_walk_spped] [int] NOT NULL, \n [standard_run_spped] [int] NOT NULL, \n [walk_speed] [int] NOT NULL, \n [run_speed] [int] NOT NULL, \n [attack_range] [decimal(10,2)] NOT NULL, \n [hidesense_range] [decimal(10,2)] NOT NULL, \n [hp] [int] NOT NULL, \n [mp] [int] NOT NULL, \n [attack_point] [int] NOT NULL, \n [magic_point] [int] NOT NULL, \n [defence] [int] NOT NULL, \n [magic_defence] [int] NOT NULL, \n [attack_speed] [int] NOT NULL, \n [magic_speed] [int] NOT NULL, \n [accuracy] [int] NOT NULL, \n [avoid] [int] NOT NULL, \n [magic_accuracy] [int] NOT NULL, \n [magic_avoid] [int] NOT NULL, \n [taming_id] [int] NOT NULL, \n [taming_percentage] [decimal(12,4)] NOT NULL, \n [taming_exp_mod] [decimal(10,2)] NOT NULL, \n [exp] [int] NOT NULL, \n [jp] [int] NOT NULL, \n [gold_drop_percentage] [int] NOT NULL, \n [gold_min] [int] NOT NULL, \n [gold_max] [int] NOT NULL, \n [chaos_drop_percentage] [int] NOT NULL, \n [chaos_min] [int] NOT NULL, \n [chaos_max] [int] NOT NULL, \n [exp_2] [int] NOT NULL, \n [jp_2] [int] NOT NULL, \n [gold_min_2] [int] NOT NULL, \n [gold_max_2] [int] NOT NULL, \n [chaos_min_2] [int] NOT NULL, \n [chaos_max_2] [int] NOT NULL, \n [drop_table_link_id] [int] NOT NULL, \n [texture_group] [int] NOT NULL, \n [local_flag] [int] NOT NULL, \n [script_on_dead] [varchar(256)] NOT NULL\n) ON [PRIMARY]\n\nGO\n\n" ;
    
            for(int i=0; i < nbloop; i++)
            {
                SQL << "INSERT INTO [Arcadia].[dbo].[MonsterResource]\n" << //Wrinting each data in SQL files
    
    			"([id] "<<
    			", [monster_group]" <<
    			", [name_id]" <<
    			", [location_id]" <<
    			", [model]" <<
    			", [motion_file_id]" <<
    			", [transform_level]" <<
    			", [walk_type]" <<
    			", [slant_type]" <<
    			", [size]" <<
    			", [scale]" <<
    			", [target_fx_size]" <<
    			", [camera_x]" <<
    			", [camera_y]" <<
    			", [camera_z]" <<
    			", [target_x]" <<
    			", [target_y]" <<
    			", [target_z]" <<
    			", [level]" <<
    			", [grp]" <<
    			", [magic_type]" <<
    			", [race]" <<
    			", [visible_range]" <<
    			", [chase_range]" <<
    			", [f_fisrt_attack]" <<
    			", [f_group_first_attack]" <<
    			", [f_response_casting]" <<
    			", [f_response_race]" <<
    			", [f_response_battle]" <<
    			", [monster_type]" <<
    			", [stat_id]" <<
    			", [fight_type]" <<
    			", [monster_skill_link_id]" <<
    			", [material]" <<
    			", [weapon_type]" <<
    			", [attack_motion_speed]" <<
    			", [ability]" <<
    			", [standard_walk_spped]" <<
    			", [standard_run_spped]" <<
    			", [walk_speed]" <<
    			", [run_speed]" <<
    			", [attack_range]" <<
    			", [hidesense_range]" <<
    			", [hp]" <<
    			", [mp]" <<
    			", [attack_point]" <<
    			", [magic_point]" <<
    			", [defence]" <<
    			", [magic_defence]" <<
    			", [attack_speed]" <<
    			", [magic_speed]" <<
    			", [accuracy]" <<
    			", [avoid]" <<
    			", [magic_accuracy]" <<
    			", [magic_avoid]" <<
    			", [taming_id]" <<
    			", [taming_percentage]" <<
    			", [taming_exp_mod]" <<
    			", [exp]" <<
    			", [jp]" <<
    			", [gold_drop_percentage]" <<
    			", [gold_min]" <<
    			", [gold_max]" <<
    			", [chaos_drop_percentage]" <<
    			", [chaos_min]" <<
    			", [chaos_max]" <<
    			", [exp_2]" <<
    			", [jp_2]" <<
    			", [gold_min_2]" <<
    			", [gold_max_2]" <<
    			", [chaos_min_2]" <<
    			", [chaos_max_2]" <<
    			", [drop_table_link_id]" <<
    			", [texture_group]" <<
    			", [local_flag]" <<
    			", [script_on_dead]) "<<
                "\nVALUES\n"<<
                "(" <<
                (int)data[i].id << "," <<
                (int)data[i].monster_group << "," <<
    			(int)data[i].name_id << "," <<
                (int)data[i].location_id << "," <<
    			'"' << (string)data[i].model << '"' << "," <<
    			(int)data[i].motion_file_id << "," <<
    			(int)data[i].transform_level << "," <<
    			(int)data[i].walk_type << "," <<
    			(int)data[i].slant_type << "," <<
    			(float)data[i].size << "," <<
    			(float)data[i].scale << "," <<
    			(float)data[i].target_fx_size << "," <<
    			(int)data[i].camera_x << "," <<
    			(int)data[i].camera_y << "," <<
    			(int)data[i].camera_z << "," <<
    			(float)data[i].target_x << "," <<
    			(float)data[i].target_y << "," <<
    			(float)data[i].target_z << "," <<
    			(int)data[i].grp << "," <<
    			(int)data[i].magic_type << "," <<
    			(int)data[i].race << "," <<
    			(int)data[i].visible_range << "," <<
    			(int)data[i].chase_range << "," <<
    			(int)data[i].f_fisrt_attack << "," <<
    			(int)data[i].f_group_first_attack << "," <<
    			(int)data[i].f_response_casting << "," <<
    			(int)data[i].f_response_race << "," <<
    			(int)data[i].f_response_battle << "," <<
    			(int)data[i].monster_type << "," <<
    			(int)data[i].stat_id << "," <<
    			(int)data[i].fight_type << "," <<
    			(int)data[i].monster_skill_link_id << "," <<
    			(int)data[i].material << "," <<
    			(int)data[i].weapon_type << "," <<
    			(int)data[i].attack_motion_speed << "," <<
    			(int)data[i].ability << "," <<
    			(int)data[i].standard_walk_spped << "," <<
    			(int)data[i].standard_run_spped << "," <<
    			(int)data[i].walk_speed << "," <<
    			(int)data[i].run_speed << "," <<
    			(float)data[i].attack_range << "," <<
    			(int)data[i].hidesense_range << "," <<
    			(int)data[i].hp << "," <<
    			(int)data[i].mp << "," <<
    			(int)data[i].attack_point << "," <<
    			(int)data[i].magic_point << "," <<
    			(int)data[i].defence << "," <<
    			(int)data[i].magic_defence << "," <<
    			(int)data[i].attack_speed << "," <<
    			(int)data[i].magic_speed << "," <<
    			(int)data[i].accuracy << "," <<
    			(int)data[i].avoid << "," <<
    			(int)data[i].magic_accuracy << "," <<
    			(int)data[i].magic_avoid << "," <<
    			(int)data[i].taming_id << "," <<
    			(float)data[i].taming_percentage << "," <<
    			(float)data[i].taming_exp_mod << "," <<
    			(int)data[i].exp << "," <<
    			(int)data[i].jp << "," <<
    			(int)data[i].gold_drop_percentage << "," <<
    			(int)data[i].gold_min << "," <<
    			(int)data[i].gold_max << "," <<
    			(int)data[i].chaos_drop_percentage << "," <<
    			(int)data[i].chaos_min << "," <<
    			(int)data[i].chaos_max << "," <<
    			(int)data[i].exp_2 << "," <<
    			(int)data[i].jp_2 << "," <<
    			(int)data[i].chaos_min_2 << "," <<
    			(int)data[i].chaos_max_2 << "," <<
    			(int)data[i].drop_table_link_id << "," <<
    			(int)data[i].texture_group << "," <<
    			(int)data[i].local_flag << "," <<
    			'\'' << (string)data[i].script_on_dead <<  '\'' << ")" <<
                "\nGo\n\n";
            }
    
            SQL.close(); //close SQL
            return 0; //exit
        }
    

    Wenn ich die Exe-Datei starte, kommt "Das funktioniert nichtmehr ..." (das übliche bei Win7 halt :D)

    Wäre sehr erfreut, wenn sich einer mein Problem annimmt !

    Gruß
    Daniel

    (PS: Diese antwort bringt mich leider auch nicht wirklich weiter ^^. Weil ich nicht weiß, wie:

    if you compile a 64bits program, RDB.read((char 😉 &nbloop,4) is not enough, as an integer will be 64bits (8 bytes), you have to add nbloop = 0 in this case before the read.
    And (string)data[i].model should not be necessary, your data is already typed, why casting them all ? And for ' " ', it should be ' \' ' (without spaces) as the " is for column names and ' for values

    )


Anmelden zum Antworten