Advertisement
Guest User

Untitled

a guest
May 10th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.07 KB | None | 0 0
  1. #include <QtSql>
  2. #include <QString>
  3. #include <QTextStream>
  4. #include <QFile>
  5. #include <stdio.h>
  6. #include <QDateTime>
  7. #include <stdlib.h>
  8. #include <sqlite3.h>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.         QDateTime qd;        
  13.     QFile f1( "result.txt" );
  14.         f1.open( QFile::WriteOnly | QFile::Text );
  15.    
  16.     freopen ("error.txt","a",stderr);
  17.         qDebug()<<"*********************Error Log*************************";
  18.     qDebug()<<qd.currentDateTime()<< "\n";
  19.  
  20.     QString par4=argv[4];
  21.     if(argc!=5 && !par4.compare("n"))
  22.     {
  23.         printf("Error: Insufficient parameters - Execute the program as: \n");
  24.         printf("./<executable file> <SQLite3 database file> <psql username> <psql pass> <y / n> [<module path>...]\n");
  25.         printf("<y / n> is for specifying whether there are modules loaded in the sqlite3 database.\n");
  26.         printf("If 'y' then mention the path to the module's library file to be loaded. Note that upto 5 modules can be loaded\n");
  27.         exit(1);
  28.     }
  29.  
  30.     if(!par4.compare("y") && argc < 5)
  31.     {
  32.         printf("Error: Please mention the module to be loaded\n");
  33.         exit(1);
  34.     }
  35.  
  36.     if(argc > 10)
  37.     {
  38.         printf("Error: Too many parameters added\n");
  39.         exit(1);
  40.     }
  41.  
  42.     QSqlDatabase db_source=QSqlDatabase::addDatabase("QSQLITE");
  43.     QSqlDatabase db_int=QSqlDatabase::addDatabase("QPSQL","second");
  44.     db_int.setHostName("localhost");
  45.         db_int.setUserName(argv[2]);
  46.         db_int.setPassword(argv[3]);
  47.     db_int.setDatabaseName("postgres");
  48.  
  49.      db_source.setDatabaseName(argv[1]);
  50.  
  51.      if(db_source.open()==false)
  52.      {
  53.          qDebug() << "Can not open source database"<<"\n" << db_source.lastError()<<"\n";
  54.              return -1;
  55.      }
  56.     if(db_int.open()==false)
  57.      {
  58.          qDebug() << "Can not open intermediate database"<<"\n"<< db_int.lastError()<<"\n";
  59.              return -1;
  60.      }
  61.      else
  62.      {
  63.             qDebug() << "Opening Source database: " << argv[1] << db_source.lastError();
  64.         qDebug() << "Opening interim database with the provided user and password" << db_int.lastError()<<"\n";
  65.        
  66.                 QTextStream stream(&f1); // This enables to program to write data to a file
  67.    
  68.             QSqlQuery db_query,schema1_query,schema2_query,col_query,schema_query;
  69.         QSqlQuery createdb_query(db_int);
  70.         createdb_query.exec("create database twincdb2int");
  71.         qDebug() << createdb_query.lastError() << "line 71" << endl;
  72.         db_int.close();
  73.        
  74.         db_int.setDatabaseName("twincdb2int");
  75.         if(db_int.open()==false)
  76.         {
  77.             qDebug() << "Can not open intermediate database twincdbint"<<"\n"<< db_int.lastError()<<"\n";
  78.                     return -1;
  79.         }
  80.         QSqlQuery psqldb_query("create table dbl(dname varchar(30),dpath varchar(60))",db_int);
  81.         qDebug() << psqldb_query.lastError() << "line 81" << endl;
  82.         QSqlQuery table_det_query,foreign_key_query,index_list_query,vtcount_query;
  83.            
  84.             db_query.exec("pragma database_list");
  85.         qDebug()<< db_query.lastError() << "line 85" << endl;
  86.             stream << "The list of databases:\n";
  87.         QSqlQuery psql_dbs_query(db_int);
  88.         psql_dbs_query.prepare("insert into dbl values(?,?)");
  89.             while(db_query.next())
  90.             {
  91.                 QString db_str0=db_query.value(0).toString();
  92.             QString db_str1=db_query.value(1).toString();
  93.             QString db_str2=db_query.value(2).toString();
  94.                            
  95.             psql_dbs_query.bindValue(0,db_str1);
  96.             psql_dbs_query.bindValue(1,db_str2);
  97.             psql_dbs_query.exec();
  98.             qDebug()<< psql_dbs_query.lastError() << "line 98" <<endl;
  99.  
  100.                 stream << db_str0 << "|" << db_str1 << "|" << db_str2 << "\n";
  101.         }    
  102.  
  103.         stream <<"\nSchema:\n";
  104.  
  105.         QString sch_str[10];
  106.         int i=0,vt=0;
  107.         schema1_query.exec("select distinct(type) from sqlite_master");
  108.         qDebug()<< schema1_query.lastError() << "line 108" << endl;
  109.         schema2_query.prepare("select count(type) from sqlite_master where type=?");
  110.  
  111.         QSqlQuery dbschema_cnt_query("create table schcnt(type varchar(15), cnt int)",db_int);
  112.         qDebug() << dbschema_cnt_query.lastError() << "line 112" << endl;
  113.  
  114.         dbschema_cnt_query.prepare("insert into schcnt values(?,?)");
  115.  
  116.         while(schema1_query.next())
  117.         {
  118.             sch_str[i]=schema1_query.value(0).toString();
  119.             schema2_query.bindValue(0,sch_str[i]);
  120.             schema2_query.exec();
  121.             qDebug()<< schema2_query.lastError() << " line 121" << endl;
  122.             if(schema2_query.next())
  123.             {  
  124.                 int sch_count=schema2_query.value(0).toInt();
  125.                 vt=0;
  126.                 if(!sch_str[i].compare("table"))
  127.                 {  
  128.                     vtcount_query.exec("select count(type) from sqlite_master where sql like 'CREATE VIRTUAL TABLE%'");
  129.                     qDebug()<< vtcount_query.lastError() << "line 129" << endl;
  130.                    
  131.                     if(vtcount_query.next())
  132.                     {
  133.                         int vtcount=vtcount_query.value(0).toInt();
  134.                         stream<< vtcount <<" Virtual Tables \n";
  135.                         vt=vtcount;
  136.                         dbschema_cnt_query.bindValue(0,"Virtual Table");
  137.                         dbschema_cnt_query.bindValue(1,vt);
  138.                         dbschema_cnt_query.exec();
  139.                         qDebug() << dbschema_cnt_query.lastError() << "line 139" << endl;
  140.                     }
  141.                 }
  142.                 stream << (sch_count - vt) << " " << sch_str[i] << "\n";
  143.                 dbschema_cnt_query.bindValue(0,sch_str[i]);
  144.                 dbschema_cnt_query.bindValue(1,(sch_count-vt));
  145.                 dbschema_cnt_query.exec();
  146.                 qDebug() << dbschema_cnt_query.lastError() << "line 146" << endl;
  147.             }
  148.             i++;
  149.         }
  150.            
  151.         int count=i,n=1;
  152.         QSqlQuery index_info_query,vtable_query,table_query,view_query,index_query,trigger_query,loadmodule_query,vtable_det_q;
  153.  
  154.         vtable_query.exec("select name,sql from sqlite_master where sql like 'CREATE VIRTUAL TABLE%'");
  155.         qDebug()<< vtable_query.lastError() << "line 155" <<endl;
  156.  
  157.         table_query.exec("select name,sql from sqlite_master where sql like 'CREATE TABLE%'");
  158.         qDebug()<< table_query.lastError() << "line 158" <<endl;
  159.        
  160.        
  161.  
  162.         QSqlQuery itbl_query(db_int),itblcol_query(db_int),iforeign_q(db_int);
  163.         itbl_query.exec("create table tblsch(tname varchar PRIMARY KEY,tsql varchar)");
  164.         qDebug()<<itbl_query.lastError() << " line 164"<<"\n";
  165.  
  166.         QSqlQuery ivtbl_query(db_int);
  167.         ivtbl_query.exec("create table vtblsch(vtname varchar PRIMARY KEY,vtsql varchar)");
  168.         qDebug()<<ivtbl_query.lastError() << " line 168"<<"\n";
  169.  
  170.         iforeign_q.exec("create table tblforkey (tblname varchar,tcol varchar,ftbl varchar,fcol varchar)");
  171.         qDebug()<<iforeign_q.lastError() << " line 171"<<"\n";
  172.  
  173.  
  174.  
  175.         QSqlQuery iidx_q(db_int),itrg_q(db_int),iview_q(db_int);
  176.         iidx_q.exec("create table indexsch (idxname varchar,tbl varchar,col varchar,sql varchar)");
  177.         qDebug()<<iidx_q.lastError() << " line 177"<<"\n";
  178.  
  179.         itrg_q.exec("create table trigsch (trigname varchar,tbl varchar, sql varchar)");
  180.         qDebug()<<itrg_q.lastError() << " line 180"<<"\n";
  181.  
  182.         iview_q.exec("create table viewsch (viewname varchar,sql varchar)");
  183.         qDebug()<<iview_q.lastError() << " line 183"<<"\n";
  184.  
  185.  
  186.  
  187.         for(int k=0;count>0;count--)
  188.         {
  189.             n=1;
  190.             if(!sch_str[k].compare("table"))
  191.             {              
  192.                 QSqlQuery itb_sch_ins_q(db_int),itb_col_ins_q(db_int),iforkey_ins_q(db_int),itb_dat_q(db_int),itb_dat_col_ins_q(db_int);
  193.                 QSqlQuery itb_dat_ins_q(db_int);
  194.  
  195.                 itb_sch_ins_q.prepare("insert into tblsch values(?,?)");
  196.  
  197.                 iforkey_ins_q.prepare("insert into tblforkey values(?,?,?,?)");
  198.  
  199.                 QSqlQuery ivtb_sch_ins_q(db_int),ivtbcol_q(db_int),ivtbcol_ins_q(db_int),vtb_data_q,ivtb_creat_q(db_int),ivtb_ins_q(db_int);
  200.                 QSqlQuery ivtb_dat_ins_q(db_int);
  201.                 ivtb_sch_ins_q.prepare("insert into vtblsch values(?,?)");
  202.  
  203.                 QSqlQuery tb_data_q;
  204.                
  205.                 if(!par4.compare("y"))
  206.                 {
  207.                     QVariant v = db_source.driver()->handle();
  208.  
  209.                     sqlite3 *handle=0;
  210.                         if (v.isValid() && strcmp(v.typeName(), "sqlite3*") == 0)
  211.                     {
  212.                         // v.data() returns a pointer to the handle
  213.                             handle = *static_cast<sqlite3 **>(v.data());
  214.                             if (handle == 0)
  215.                         {      
  216.                                     qDebug() << "Could not get sqlite handle";
  217.                             }
  218.                         }
  219.                     else
  220.                     {
  221.                             qDebug() << "handle variant returned typename " << v.typeName();
  222.                         }
  223.  
  224.                     sqlite3_enable_load_extension(handle, 1);
  225.  
  226.                     int tot_par=argc;
  227.                     QSqlQuery load_module_q;
  228.  
  229.                     while((tot_par-5)>0)
  230.                     {
  231.                         QString lmod=argv[tot_par-1];
  232.                         load_module_q.exec("select load_extension('" + lmod + "')");
  233.                         qDebug() << load_module_q.lastError() << "line 233" << endl;
  234.                         tot_par--;
  235.                     }
  236.    
  237.                     stream << "\nThe list and details of Virtual Tables:\n";
  238.                     while(vtable_query.next())
  239.                     {
  240.                         stream << n <<". ";
  241.                         QString vtable_name=vtable_query.value(0).toString();
  242.                         QString vtable_sql=vtable_query.value(1).toString();
  243.                         stream << vtable_name <<"\n   SQL code:\n   "<< vtable_sql << "\n\n   ";
  244.                         ivtb_sch_ins_q.bindValue(0,vtable_name);
  245.                         ivtb_sch_ins_q.bindValue(1,vtable_sql);
  246.                         ivtb_sch_ins_q.exec();
  247.                         qDebug() << ivtb_sch_ins_q.lastError() << "line 247" << endl;
  248.                        
  249.                         vtable_det_q.exec("pragma table_info("+vtable_name+")");
  250.                         qDebug()<< vtable_det_q.lastError() << "line 250" << endl;
  251.    
  252.                         ivtbcol_q.exec("create table "+vtable_name+"_d (coln varchar,dtype varchar)");
  253.                         qDebug() << ivtbcol_q.lastError() << "line 253" << endl;
  254.  
  255.                         ivtbcol_ins_q.prepare("insert into "+vtable_name+"_d values(?,'text')");
  256.                    
  257.                         ivtb_creat_q.exec("create table "+vtable_name+" ()");
  258.                         qDebug() << ivtb_creat_q.lastError() << "line 258" << endl;
  259.            
  260.                         stream<<"Columns and their datatypes:\n   ";
  261.                         int j=0;
  262.                         while(vtable_det_q.next())
  263.                         {
  264.                             QString table_det1=vtable_det_q.value(1).toString();
  265.                            
  266.                             ivtbcol_ins_q.bindValue(0,table_det1);
  267.                             ivtbcol_ins_q.exec();
  268.                             qDebug() << ivtbcol_ins_q.lastError() << endl;
  269.  
  270.                             ivtb_ins_q.exec("alter table "+vtable_name+" ADD "+table_det1+" TEXT");
  271.                             qDebug() << ivtb_ins_q.lastError() << "line 271" << endl;
  272.                             j++;
  273.                             stream << table_det1 << " TEXT\n   ";
  274.                         }
  275.                    
  276.                         stream <<"\n   The data:\n";
  277.                    
  278.                             vtb_data_q.exec("select * from "+vtable_name);
  279.                         qDebug() << vtb_data_q.lastError() << "line 279" << endl;
  280.                
  281.                         QString dat_ins="insert into "+vtable_name+" values (";
  282.                        
  283.                                 while(vtb_data_q.next())
  284.                                 {
  285.                                     for(int k=0;k<j;k++)
  286.                                     {
  287.                                             QString data_str=vtb_data_q.value(k).toString();
  288.                                             if(k!=(j-1))
  289.                                                     stream << data_str << "|";
  290.                                             else
  291.                                                     stream << data_str << "\n";
  292.    
  293.                                    if(!data_str.compare(""))
  294.                                         data_str="null";
  295.                                    else
  296.                                          data_str="'"+data_str+"'";
  297.    
  298.                                    dat_ins=dat_ins+data_str+",";
  299.                                        }
  300.                             dat_ins.append(")");
  301.                             int cpos=dat_ins.indexOf(",)");
  302.                                     dat_ins.replace(cpos,1,"");
  303.  
  304.                             ivtb_dat_ins_q.exec(dat_ins);
  305.                             qDebug() << itb_dat_ins_q.lastError() << "line 305 " <<vtable_name << endl;
  306.  
  307.                             dat_ins="insert into "+vtable_name+" values (";
  308.                                 }  
  309.  
  310.                         stream<<"\n";
  311.                         n++;
  312.                     }
  313.                 }
  314.                 n=1;
  315.                 stream << "\nThe list and details of Tables:\n";
  316.                 while(table_query.next())
  317.                 {
  318.                     stream << n <<". ";
  319.                     QString table_name=table_query.value(0).toString();
  320.                     QString table_sql=table_query.value(1).toString();
  321.                     stream << table_name <<"\n   SQL code:\n   "<< table_sql << "\n\n   ";
  322.                     table_det_query.exec("pragma table_info("+table_name+")");
  323.                     qDebug()<< table_det_query.lastError() << "line 323"<<endl;
  324.  
  325.                     itb_sch_ins_q.bindValue(0,table_name);
  326.                     itb_sch_ins_q.bindValue(1,table_sql);
  327.                     itb_sch_ins_q.exec();
  328.                     qDebug()<< itb_sch_ins_q.lastError() << "line 328" << endl;
  329.  
  330.                     itblcol_query.exec("create table "+table_name+"_d (coln varchar,dtype varchar,prim int)");
  331.                     qDebug() << itblcol_query.lastError() << "line 331" << endl;
  332.  
  333.                     stream<<"Columns and their datatypes:\n   ";
  334.                    
  335.                     itb_col_ins_q.prepare("insert into "+table_name+"_d values(?,?,?)");
  336.                    
  337.                     itb_dat_q.exec("create table "+table_name+" ()");
  338.                     qDebug() << itb_dat_q.lastError() << "line 338" << endl;
  339.                    
  340.                     int j=0;
  341.                     while(table_det_query.next())
  342.                     {
  343.                         QString table_det1=table_det_query.value(1).toString();
  344.                         QString table_det2=table_det_query.value(2).toString();
  345.                         int table_det3=table_det_query.value(5).toInt();
  346.                         stream << table_det1 << " " <<table_det2<<" ";
  347.                         if(table_det3 != 1)
  348.                             stream << "\n   ";
  349.                         else
  350.                             stream <<"PRIMARY KEY\n   ";
  351.                         itb_col_ins_q.bindValue(0,table_det1);
  352.                         itb_col_ins_q.bindValue(1,table_det2);
  353.                         itb_col_ins_q.bindValue(2,table_det3);
  354.                         itb_col_ins_q.exec();
  355.                         qDebug() << itb_col_ins_q.lastError() << "line 355" << endl;
  356.            
  357.                         if(table_det2.contains("int", Qt::CaseInsensitive))
  358.                             table_det2="int";
  359.                         else if(table_det2.contains("blob", Qt::CaseInsensitive))
  360.                             table_det2="bytea";
  361.                         else if(!table_det2.compare(""))
  362.                             table_det2="varchar";
  363.  
  364.                         itb_dat_col_ins_q.exec("alter table "+table_name+" ADD "+table_det1+" "+table_det2);
  365.                         qDebug() << itb_dat_col_ins_q.lastError() << "line 365" << endl;
  366.                         j++;
  367.                     }
  368.                     stream<<"\n   List of foreign keys:\n   ";
  369.                     foreign_key_query.exec("pragma foreign_key_list("+table_name+")");
  370.                     qDebug()<< foreign_key_query.lastError() << "line 370"<<endl;
  371.  
  372.                     while(foreign_key_query.next())
  373.                     {
  374.                         QString table_foreign0=foreign_key_query.value(3).toString();
  375.                         QString table_foreign1=foreign_key_query.value(2).toString();
  376.                         QString table_foreign2=foreign_key_query.value(4).toString();
  377.                         stream<<table_foreign0<< " REFERENCES " << table_foreign1 <<"("<<table_foreign2<<")"<<"\n   ";
  378.  
  379.                         iforkey_ins_q.bindValue(0,table_name);
  380.                         iforkey_ins_q.bindValue(1,table_foreign0);
  381.                         iforkey_ins_q.bindValue(2,table_foreign1);
  382.                         iforkey_ins_q.bindValue(3,table_foreign2);
  383.                         iforkey_ins_q.exec();
  384.                         qDebug() << iforkey_ins_q.lastError() << "line 384" << endl;
  385.  
  386.                     }
  387.  
  388.                     stream<<"\n   The list of index associated with this table:\n   ";
  389.                     index_list_query.exec("pragma index_list("+table_name+")");
  390.                     qDebug()<< index_list_query.lastError() << "line 390"<<endl;
  391.  
  392.                     while(index_list_query.next())
  393.                     {
  394.                         QString table_index1=index_list_query.value(1).toString();
  395.                         int table_index2=index_list_query.value(2).toInt();
  396.                         stream << table_index1 << " ";
  397.                         if(table_index2 == 1)
  398.                             stream << "UNIQUE";
  399.                         stream<<"\n   ";
  400.                     }
  401.                    
  402.                     stream <<"\n   The data:\n";
  403.                    
  404.                         tb_data_q.exec("select * from "+table_name);
  405.                     qDebug() << tb_data_q.lastError() << "line 405" << endl;
  406.            
  407.                     QString dat_ins="insert into "+table_name+" values (";
  408.                    
  409.                             while(tb_data_q.next())
  410.                             {
  411.                                 for(int k=0;k<j;k++)
  412.                                 {
  413.                                         QString data_str=tb_data_q.value(k).toString();
  414.                                         if(k!=(j-1))
  415.                                                 stream << data_str << "|";
  416.                                         else
  417.                                                 stream << data_str << "\n";
  418.  
  419.                                if(!data_str.compare(""))
  420.                                     data_str="null";
  421.                                else
  422.                                      data_str="'"+data_str+"'";
  423.  
  424.                                dat_ins=dat_ins+data_str+",";
  425.                                 }
  426.                         dat_ins.append(")");
  427.                         int cpos=dat_ins.indexOf(",)");
  428.                                 dat_ins.replace(cpos,1,"");
  429.                         itb_dat_ins_q.exec(dat_ins);
  430.                         qDebug() << itb_dat_ins_q.lastError() << "line 430 " <<table_name << endl;
  431.                         dat_ins="insert into "+table_name+" values (";
  432.                             }  
  433.                     stream << "\n";
  434.                     n++;
  435.                 }
  436.             }
  437.             else if(!sch_str[k].compare("view"))
  438.             {
  439.                 n=1;
  440.                 view_query.exec("select name,tbl_name,sql from sqlite_master where type='"+sch_str[k]+"' order by name asc");
  441.                 qDebug()<< view_query.lastError() << "line 441" <<endl;
  442.                
  443.                 QSqlQuery iview_ins_q(db_int),iview_col_q(db_int),iview_col_ins_q(db_int),iview_create_q(db_int);
  444.                 iview_ins_q.prepare("insert into viewsch values(?,?)");
  445.  
  446.                 stream << "\nThe list and details of View:\n";
  447.                 while(view_query.next())
  448.                 {
  449.                     stream << n <<". ";
  450.                     QString view_name=view_query.value(0).toString();
  451.                     QString view_sql=view_query.value(2).toString();
  452.                     stream << view_name <<"\n   SQL code:\n   "<< view_sql << "\n\n   ";
  453.                     table_det_query.exec("pragma table_info("+view_name+")");
  454.                    
  455.                     qDebug()<< table_det_query.lastError() << "line 455"<<endl;
  456.  
  457.                     iview_ins_q.bindValue(0,view_name);
  458.                     iview_ins_q.bindValue(1,view_sql);
  459.                     iview_ins_q.exec();
  460.                     qDebug() << iview_ins_q.lastError() << "line 460" << endl;
  461.  
  462.                     iview_col_q.exec("create table "+view_name+"_d (colname varchar,coltype varchar)");
  463.                     qDebug() << iview_col_q.lastError() << "line 463" << endl;
  464.  
  465.                     stream<<"Columns and their datatypes:\n   ";
  466.                     iview_col_ins_q.prepare("insert into "+view_name+"_d values (?,?)");
  467.  
  468.                     while(table_det_query.next())
  469.                     {
  470.                         QString view_det1=table_det_query.value(1).toString();
  471.                         QString view_det2=table_det_query.value(2).toString();
  472.                         stream << view_det1 << " " <<view_det2<<"\n   ";
  473.  
  474.                         iview_col_ins_q.bindValue(0,view_det1);
  475.                         iview_col_ins_q.bindValue(1,view_det2);
  476.                         iview_col_ins_q.exec();
  477.                         qDebug() << iview_col_ins_q.lastError() << "line 477" << endl;
  478.                     }
  479.                     iview_create_q.exec(view_sql);
  480.                     qDebug() << iview_create_q.lastError() << "line 480" << endl;
  481.                     n++;
  482.                 }
  483.             }
  484.             else if( !sch_str[k].compare("index"))
  485.             {
  486.                 stream << "\nThe list and details of " << sch_str[k] <<":\n";
  487.                 index_query.exec("select name,tbl_name,sql from sqlite_master where type='"+sch_str[k]+"' order by name asc");
  488.                 qDebug()<< index_query.lastError() << "line 488" <<endl;
  489.  
  490.                 QSqlQuery iidx_ins_q(db_int);
  491.                 iidx_ins_q.prepare("insert into indexsch values(?,?,?,?)");
  492.  
  493.                 while(index_query.next())
  494.                 {
  495.                     stream << n <<". ";
  496.                     QString index_name=index_query.value(0).toString();
  497.                     QString index_table=index_query.value(1).toString();
  498.                     QString index_sql=index_query.value(2).toString();
  499.                     stream<<index_name <<"\n   associated with table: "<< index_table;
  500.                     index_info_query.exec("pragma index_info("+index_name+")");
  501.                     qDebug()<< index_info_query.lastError() << "line 501"<<endl;
  502.  
  503.                     if(index_info_query.next())
  504.                     {
  505.                         QString index_col=index_info_query.value(2).toString();
  506.                         stream<<"   column: "<<index_col;
  507.                         stream<<"\n   SQL code:\n   "<<index_sql<<"\n\n";
  508.                        
  509.                         iidx_ins_q.bindValue(0,index_name);
  510.                         iidx_ins_q.bindValue(1,index_table);
  511.                         iidx_ins_q.bindValue(2,index_col);
  512.                         iidx_ins_q.bindValue(3,index_sql);
  513.                         iidx_ins_q.exec();
  514.                         qDebug() << iidx_ins_q.lastError() << "line 514" << endl;
  515.                     }
  516.                     n++;
  517.                 }
  518.             }
  519.             else
  520.             {
  521.                 stream << "\nThe list and details of " << sch_str[k] <<":\n";
  522.                 trigger_query.exec("select name,tbl_name,sql from sqlite_master where type='"+sch_str[k]+"' order by name asc");
  523.                 qDebug()<< trigger_query.lastError() << "line 523" <<endl;
  524.  
  525.                 QSqlQuery itrig_ins_q(db_int);
  526.                 itrig_ins_q.prepare("insert into trigsch values(?,?,?)");
  527.                    
  528.                 while(trigger_query.next())
  529.                 {
  530.                     stream << n <<". ";
  531.                     QString trig_name=trigger_query.value(0).toString();
  532.                     QString trig_tbl=trigger_query.value(1).toString();
  533.                     QString trig_sql=trigger_query.value(2).toString();
  534.                     stream << trig_name <<"\n   On table: "<<trig_tbl<<"\n   SQL code:\n   "<< trig_sql << "\n\n";
  535.  
  536.                     itrig_ins_q.bindValue(0,trig_name);
  537.                     itrig_ins_q.bindValue(1,trig_tbl);
  538.                     itrig_ins_q.bindValue(2,trig_sql);
  539.                     itrig_ins_q.exec();
  540.                     qDebug() << itrig_ins_q.lastError() << "line 540" << endl;
  541.  
  542.                     n++;
  543.                 }
  544.             }
  545.             k++;
  546.         }
  547.        
  548.         qDebug() << "***********************************************************" << "\n\n";
  549.         f1.close();
  550.         fclose (stderr);
  551.         db_source.close();
  552.         db_int.close();
  553.  
  554.             return 1;
  555.     }  
  556. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement