/*
* Copyright (C) 2005-2011 MaNGOS
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "defines.h"
int main(int argc, char* argv[])
{
char sPGhost[26], sPGport[26], sPGdb[26], sPGuser[26], sPGpass[26];
printf("Postgres connection settings\n Host>");
scanf("%s",sPGhost);
printf(" Port>");
scanf("%s",sPGport);
printf(" Base>");
scanf("%s",sPGdb);
printf(" User>");
scanf("%s",sPGuser);
printf(" Pass>");
scanf("%s",sPGpass);
///////////////////////////////
///////PGSQL Connect///////////
///////////////////////////////
PGconn *mPGconn=NULL;
mPGconn = PQsetdbLogin(sPGhost,sPGport, NULL, NULL, sPGdb, sPGuser, sPGpass);
if (PQstatus(mPGconn) != CONNECTION_OK)
{
printf("Could not connect to Postgre database at [%s]: \n %s\n",sPGhost, PQerrorMessage(mPGconn));
PQfinish(mPGconn);
return 1;
}
else
{
printf("Connected to Postgre database at [%s]\n", sPGhost);
printf(" PostgreSQL server ver: [%d]\n\n",PQserverVersion(mPGconn));
}
/// Set dummy notice processor
PQsetNoticeProcessor(mPGconn, pg_notice, mPGconn);
///////////////////////////////
///////MySQL Connect///////////
///////////////////////////////
MYSQL *mysqlInit;
mysqlInit = mysql_init(NULL);
if (!mysqlInit)
{
printf( "Could not initialize Mysql connection\n" );
return 1;
}
char sMYhost[26], sMYdb[26], sMYuser[26], sMYpass[26];
int iMYport;
printf("Mysql connection settings \n Host>");
scanf("%s",sMYhost);
printf(" Port>");
scanf("%d",&iMYport);
printf(" Base>");
scanf("%s",sMYdb);
printf(" User>");
scanf("%s",sMYuser);
printf(" Pass>");
scanf("%s",sMYpass);
mysql_options(mysqlInit,MYSQL_SET_CHARSET_NAME,"utf8");
MYSQL *mMysql;
mMysql = mysql_real_connect(mysqlInit, sMYhost, sMYuser, sMYpass, sMYdb, iMYport, NULL, 0);
if (mMysql)
{
printf( "Connected to MySQL database at [%s] \n", sMYhost);
printf( " MySQL client library: [%s] \n", mysql_get_client_info());
printf( " MySQL server ver: [%s] \n\n", mysql_get_server_info( mMysql));
}
else
{
printf("Could not connect to MySQL database at [%s]:\n %s\n", sMYhost ,mysql_error(mysqlInit));
mysql_close(mysqlInit);
return 1;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
MYSQL_RES *result = NULL;
MYSQL_ROW row;
MYSQL_FIELD *fields = NULL;
uint64 rowCount = 0;
uint32 fieldCount =0;
result = mysql_list_tables( mMysql , NULL );
rowCount = mysql_num_rows(result);
/***********************/
/* get list of tables */
/***********************/
T_TableList mTableList;
mTableList.reserve((size_t)rowCount);
while( (row = mysql_fetch_row(result)) !=NULL )
{
for (uint32 i = 0;i