From: Florian G. <re...@us...> - 2007-03-26 22:26:47
|
Update of /cvsroot/perfparse/_perfparse/db_tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26018/db_tools Modified Files: convert.c Log Message: now really start convert Index: convert.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/db_tools/convert.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** convert.c 22 Mar 2007 00:21:51 -0000 1.21 --- convert.c 26 Mar 2007 22:26:45 -0000 1.22 *************** *** 62,66 **** void addTableRawSummaryData (); void pp_mysql_convert_sql_failure(char*f,int l, const char*str, const char *error); ! void dbtool_mysql_query(const char *sql, MYSQL *p_tmp_db_mysql, MYSQL_RES *p_tmp_query_result); void dbtool_freeResult(MYSQL_RES *p_tmp_query_result); int dbtool_rows(MYSQL_RES *p_tmp_query_result); --- 62,66 ---- void addTableRawSummaryData (); void pp_mysql_convert_sql_failure(char*f,int l, const char*str, const char *error); ! MYSQL_RES *dbtool_mysql_query(const char *sql, MYSQL *p_tmp_db_mysql, MYSQL_RES *p_tmp_query_result); void dbtool_freeResult(MYSQL_RES *p_tmp_query_result); int dbtool_rows(MYSQL_RES *p_tmp_query_result); *************** *** 142,147 **** GString *gsODBSql = g_string_new (""); ! int iODBnumrows; ! int iNDBnumrows; int i,x,y; --- 142,148 ---- GString *gsODBSql = g_string_new (""); ! int iODBnumrows, iODBnumFields; ! int iNDBnumrows, iNDBnumFields; ! unsigned long *piODBlengths, *piNDBlengths; int i,x,y; *************** *** 235,241 **** sODBdatabase=malloc(65); ! printw(_("Database Name (default: perfparse): ")); refresh(); ! read_string_from_line(sODBdatabase,64,"perfparse"); --- 236,242 ---- sODBdatabase=malloc(65); ! printw(_("Database Name (default: perfparse_old): ")); refresh(); ! read_string_from_line(sODBdatabase,64,"perfparse_old"); *************** *** 279,285 **** sNDBdatabase=malloc(65); ! printw(_("Database Name (default: perfparse): ")); refresh(); ! read_string_from_line(sNDBdatabase,64,"perfparse"); --- 280,286 ---- sNDBdatabase=malloc(65); ! printw(_("Database Name (default: perfparse_new): ")); refresh(); ! read_string_from_line(sNDBdatabase,64,"perfparse_new"); *************** *** 325,345 **** } ! printw(_("Copying data of old perfdata_host_group to new perfdata_groups table.\n")); printw(_("(Step %d of %d)\n"),iStep,iNumSteps); refresh(); g_string_printf(gsODBSql, "select * from perfdata_host_group"); ! dbtool_mysql_query(gsODBSql->str, &db_mysql_old, query_result_old); iODBnumrows=dbtool_rows(query_result_old); getyx(stdscr,y,x); ! for (i=1 ; i<=iODBnumrows; i++) { move(y,x); printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); ! // todo: make loop use mysql_fetch_row and fix next line ! g_string_printf(gsNDBSql, "insert into perfdata_groups(group_name) values('%s')"); dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); } printw(_("\ndone\n")); refresh(); /* int i_steps=20; --- 326,382 ---- } ! // Step 1 printw(_("(Step %d of %d)\n"),iStep,iNumSteps); + printw(_("Copying data of old perfdata_host_group to new perfdata_groups table.\n")); refresh(); g_string_printf(gsODBSql, "select * from perfdata_host_group"); ! query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); ! if((iODBnumFields=mysql_num_fields(query_result_old))!=1) { ! printw(_("Original perfdata_host_groups table modified! Bailing out")); ! exit(EXIT_FAILURE); ! } iODBnumrows=dbtool_rows(query_result_old); + printw("Affected rows: %d\n",iODBnumrows); getyx(stdscr,y,x); ! i=0; ! while ((result_row_old=mysql_fetch_row(query_result_old))) { ! i++; move(y,x); + piODBlengths=mysql_fetch_lengths(query_result_old); printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); ! g_string_printf(gsNDBSql, "insert ignore into perfdata_groups(group_name) values('%.*s')",(int) piODBlengths[0],result_row_old[0]); dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); } printw(_("\ndone\n")); refresh(); + // Step 2 + iStep++; + printw(_("(Step %d of %d)\n"),iStep,iNumSteps); + printw(_("Copying data of perfdata_host table.\n")); + refresh(); + + g_string_printf(gsODBSql, "select * from perfdata_host"); + query_result_old=dbtool_mysql_query(gsODBSql->str, &db_mysql_old,query_result_old); + if((iODBnumFields=mysql_num_fields(query_result_old))!=10) { + printw(_("Original perfdata_host table modified! Bailing out")); + exit(EXIT_FAILURE); + } + iODBnumrows=dbtool_rows(query_result_old); + printw("Affected rows: %d\n",iODBnumrows); + getyx(stdscr,y,x); + i=0; + while ((result_row_old=mysql_fetch_row(query_result_old))) { + i++; + move(y,x); + piODBlengths=mysql_fetch_lengths(query_result_old); + printw(_("Copying entry %d/%d"),i,iODBnumrows); refresh(); + //g_string_printf(gsNDBSql, ""); // todo: copy policies, host info and popuplate perfdata_host_groups + //dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); + } + printw(_("\ndone\n")); refresh(); + + + /* int i_steps=20; *************** *** 545,549 **** } ! void dbtool_mysql_query(const char *sql, MYSQL *p_tmp_db_mysql, MYSQL_RES *p_tmp_query_result) { #ifdef SHOW_SQL --- 582,586 ---- } ! MYSQL_RES *dbtool_mysql_query(const char *sql, MYSQL *p_tmp_db_mysql, MYSQL_RES *p_tmp_query_result) { #ifdef SHOW_SQL *************** *** 567,571 **** fflush(stdout); #endif ! } --- 604,609 ---- fflush(stdout); #endif ! return(p_tmp_query_result); ! } |