Guest User

Untitled

a guest
Nov 18th, 2012
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. //RDB TO SQL FOR db_creaturefarm by Gr4ph0s
  2. //RELEASE ON EPVP
  3. #include <iostream>
  4. #include <fstream>
  5. using namespace std;
  6.  
  7. struct db_creaturefarm {
  8.   char rate;
  9.   char form;
  10.   char enhance_level;
  11.   char ticket_count;
  12. };
  13.  
  14. int main()
  15. {
  16.     int nbloop; //var for count number of loop
  17.     ifstream RDB; //stream for read rdb
  18.     ofstream SQL; //stream for write sql
  19.     RDB.open("db_creaturefarm.rdb", ios::in | ios::binary); //open RDB file
  20.  
  21.     if(!RDB)//if the file can't be open
  22.     {
  23.         cout << "Cannot open file.\n";
  24.         return 1;
  25.     }
  26.     SQL.open("db_creaturefarm.sql"); //open SQL file
  27.     RDB.seekg(128, ios::beg); //We go over the header(128empty bit)
  28.     RDB.read((char *) &nbloop,4);//we read 4bit(int) corresponding to the nb of line
  29.  
  30.     db_creaturefarm data[nbloop];//create array who will contening each information
  31.     for(int i=0; i<nbloop; i++) //loop for read all data
  32.     {
  33.         RDB.read((char *) &data[i], sizeof(db_creaturefarm));//put each data from structure into
  34.     }
  35.  
  36.     RDB.close(); //close RDB
  37.  
  38.     if(!RDB.good()) //If error durring reading(some time because you try to read more than you can)
  39.     {
  40.         cout << "A file error occurred.\n";
  41.         return 1;
  42.     }
  43.     //Wrinting Drop & create for CreatureFarmResource
  44.      SQL << "USE [Arcadia]\nGO\n/****** Object:  Table [dbo].[CreatureFarmResource]    Script Date: 18/11/2012 16:55:03 ******/\nDROP TABLE [dbo].[CreatureFarmResource]\nGO\n\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nCREATE TABLE [dbo].[CreatureFarmResource](\n [rate] [int] NOT NULL,\n [form] [int] NOT NULL,\n [enhance_level] [int] NOT NULL,\n [ticket_count] [int] NOT NULL\n) ON [PRIMARY]\n\nGO\n\n" ;
  45.  
  46.  
  47.     for(int i=0; i < nbloop; i++)
  48.     {
  49.         SQL << "INSERT INTO [Arcadia].[dbo].[CreatureFarmResource]\n" << //Wrinting each data in SQL files
  50.         "([rate] "<<
  51.         ",[form]" <<
  52.         ",[enhance_level] "<<
  53.         ",[ticket_count]) "<<
  54.         "\nVALUES\n"<<
  55.         "(" <<
  56.         (int)data[i].rate << "," <<
  57.         (int)data[i].form << "," <<
  58.         (int)data[i].enhance_level << "," <<
  59.         (int)data[i].ticket_count << ")" <<
  60.         "\nGo\n\n";
  61.     }
  62.  
  63.     SQL.close(); //close SQL
  64.     return 0; //exit
  65. }
Advertisement
Add Comment
Please, Sign In to add comment