From: Florian G. <re...@us...> - 2007-03-22 00:21:55
|
Update of /cvsroot/perfparse/_perfparse/db_tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30719/db_tools Modified Files: convert.c Log Message: more ... Index: convert.c =================================================================== RCS file: /cvsroot/perfparse/_perfparse/db_tools/convert.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** convert.c 20 Mar 2007 23:17:38 -0000 1.20 --- convert.c 22 Mar 2007 00:21:51 -0000 1.21 *************** *** 65,69 **** void dbtool_freeResult(MYSQL_RES *p_tmp_query_result); int dbtool_rows(MYSQL_RES *p_tmp_query_result); - char *read_line (char *buf, size_t length); char *read_string_from_line(char *buf, size_t length, const char* defaultval); int read_int_from_line(int defaultval); --- 65,68 ---- *************** *** 261,299 **** sNDBsocket=config_get_value_as_string(CONFIG_ITEM_ID_DB_SOCKET); } else { //ask user ! printf(_("Please enter the connection data for the new database below:\n")); sNDBhost=malloc(65); ! printf(_("Database Host: ")); ! fscanf(stdin,"%s64",sNDBhost); ! sNDBuser=malloc(65); ! printf(_("Database User: ")); ! fscanf(stdin,"%s64",sNDBuser); sNDBpass=malloc(65); ! printf(_("Database Password: ")); ! fscanf(stdin,"%s64",sNDBpass); sNDBdatabase=malloc(65); ! printf(_("Database Name: ")); ! fscanf(stdin,"%s64",sNDBdatabase); ! printf(_("Database Port: ")); ! fscanf(stdin,"%d",&iNDBport); ! sNDBsocket=malloc(65); ! printf(_("Database Socket: ")); ! fscanf(stdin,"%s64",sNDBsocket); ! ! } ! printf(_("Summary old Database:\nDatabase Host: '%s'\nDatabase User: '%s'\nDatabase Password: '%s'\nDatabase Name: '%s'\nDatabase Port: '%d'\nDatabase Socket: '%s'\n"), sODBhost,sODBuser,sODBpass,sODBdatabase,iODBport,sODBsocket); ! printf(_("Summary new Database:\nDatabase Host: '%s'\nDatabase User: '%s'\nDatabase Password: '%s'\nDatabase Name: '%s'\nDatabase Port: '%d'\nDatabase Socket: '%s'\n"), sNDBhost,sNDBuser,sNDBpass,sNDBdatabase,iNDBport,sNDBsocket); // connect to both databases ! if (!mysql_init (&db_mysql_old)) { ! printf(_("Cannot initialise MySQL\n")); exit(EXIT_FAILURE); } --- 260,307 ---- sNDBsocket=config_get_value_as_string(CONFIG_ITEM_ID_DB_SOCKET); } else { //ask user ! printw(_("Please enter the connection data for the new database below:\n")); sNDBhost=malloc(65); ! printw(_("Database Host (default: localhost): ")); ! refresh(); ! read_string_from_line(sNDBhost,64,"localhost"); ! sNDBuser=malloc(65); ! printw(_("Database User (default: root): ")); ! refresh(); ! read_string_from_line(sNDBuser,64,"root"); ! sNDBpass=malloc(65); ! printw(_("Database Password: ")); ! refresh(); ! read_string_from_line(sNDBpass,64,""); sNDBdatabase=malloc(65); ! printw(_("Database Name (default: perfparse): ")); ! refresh(); ! read_string_from_line(sNDBdatabase,64,"perfparse"); ! ! printw(_("Database Port (defualt: none): ")); ! refresh(); ! iNDBport=read_int_from_line(FALSE); ! sNDBsocket=malloc(65); ! printw(_("Database Socket (default: none): ")); ! refresh(); ! read_string_from_line(sNDBsocket,64,""); ! ! } ! printw(_("Summary old Database:\nDatabase Host: '%s'\nDatabase User: '%s'\nDatabase Password: '%s'\nDatabase Name: '%s'\nDatabase Port: '%d'\nDatabase Socket: '%s'\n"), sODBhost,sODBuser,sODBpass,sODBdatabase,iODBport,sODBsocket); ! printw(_("Summary new Database:\nDatabase Host: '%s'\nDatabase User: '%s'\nDatabase Password: '%s'\nDatabase Name: '%s'\nDatabase Port: '%d'\nDatabase Socket: '%s'\n"), sNDBhost,sNDBuser,sNDBpass,sNDBdatabase,iNDBport,sNDBsocket); + refresh(); // connect to both databases ! if (!mysql_init (&db_mysql_old) || !mysql_init (&db_mysql_new)) { ! printw(_("Cannot initialise MySQL\n")); refresh(); exit(EXIT_FAILURE); } *************** *** 302,307 **** sODBhost,sODBuser,sODBpass,sODBdatabase, iODBport,sODBsocket,0)) { ! printf(_("Cannot connect to old database. Errormessage: %s"), mysql_error(&db_mysql_old)); exit(EXIT_FAILURE); } --- 310,316 ---- sODBhost,sODBuser,sODBpass,sODBdatabase, iODBport,sODBsocket,0)) { ! printw(_("Cannot connect to old database. Errormessage: %s"), mysql_error(&db_mysql_old)); + refresh(); exit(EXIT_FAILURE); } *************** *** 310,331 **** sNDBhost,sNDBuser,sNDBpass,sNDBdatabase, iNDBport,sNDBsocket,0)) { ! printf(_("Cannot connect to new database. Errormessage: %s"), mysql_error(&db_mysql_new)); exit(EXIT_FAILURE); } ! printf(_("Copying data of old perfdata_host_group to new perfdata_groups table.\n")); ! printf(_("(Step %d of %d)\n"),iStep,iNumSteps); 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); for (i=1 ; i<=iODBnumrows; i++) { ! printf(_("Copying entry %d/%d"),i,iODBnumrows); g_string_printf(gsNDBSql, "insert into perfdata_groups(group_name) values('%s')"); dbtool_mysql_query(gsNDBSql->str, &db_mysql_new, query_result_new); - printf("\r"); } ! printf(_("\ndone\n")); /* --- 319,344 ---- sNDBhost,sNDBuser,sNDBpass,sNDBdatabase, iNDBport,sNDBsocket,0)) { ! printw(_("Cannot connect to new database. Errormessage: %s"), mysql_error(&db_mysql_new)); + refresh(); exit(EXIT_FAILURE); } ! 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(); /* *************** *** 479,499 **** } - char *read_line (char *buf, size_t length) - { - char *input_line; - - if ((input_line = fgets (buf, length, stdin))) { - size_t last = strlen (buf) - 1; - - if (buf[last] == '\n') { - buf[last] = '\0'; - } else { - //clear stdin - fscanf (stdin, "%*[^\n]"); - (void) fgetc (stdin); - } - } - return input_line; - } char *read_string_from_line(char *buf, size_t length, const char* defaultval) { --- 492,495 ---- *************** *** 538,542 **** } if(defaultval==FALSE) { ! printw("none"); } else { printw("%d\n",defaultval); --- 534,538 ---- } if(defaultval==FALSE) { ! printw("none\n"); } else { printw("%d\n",defaultval); *************** *** 558,562 **** if (mysql_query(p_tmp_db_mysql, sql)) { ! printf(_("A error occured executing the sql command %s. The error message is: %s"), sql, mysql_error(p_tmp_db_mysql)); exit(EXIT_FAILURE); --- 554,558 ---- if (mysql_query(p_tmp_db_mysql, sql)) { ! printw(_("A error occured executing the sql command %s. The error message is: %s"), sql, mysql_error(p_tmp_db_mysql)); exit(EXIT_FAILURE); *************** *** 568,572 **** #ifdef SHOW_SQL ! printf("Rows: %d\n", dbtool_rows(p_tmp_query_result)); fflush(stdout); #endif --- 564,568 ---- #ifdef SHOW_SQL ! printw("Rows: %d\n", dbtool_rows(p_tmp_query_result)); fflush(stdout); #endif |