Пример #1
0
        static ConEgg OpenDB(string DBname)
        {
            ConEgg ce;
            var    DB = new MyDataBase(DBname);
            // DB.DBCreation();
            SQLiteConnection m_dbConnection = new SQLiteConnection(string.Format(
                                                                       "Data Source={0};Version=3;", DB.DBname));

            m_dbConnection.Open();
            // SQLiteCommand command = new SQLiteCommand(m_dbConnection);
            //  begin transaction
            SQLiteCommand command = new SQLiteCommand("begin", m_dbConnection);

            command.ExecuteNonQuery();



            ce.todoOK    = true;
            ce.SQLiteCon = m_dbConnection;
            ce.SQLComm   = command;

            return(ce);
        }
Пример #2
0
        static bool CreateDB(string DBname)
        {
            File.Delete(DBname);                 // first delete the file
            SQLiteConnection.CreateFile(DBname); // Create DB
            var DB = new MyDataBase(DBname);
            SQLiteConnection m_dbConnection = new SQLiteConnection(string.Format(
                                                                       "Data Source={0};Version=3;", DB.DBname));

            m_dbConnection.Open();
            SQLiteCommand command = new SQLiteCommand(m_dbConnection);

            // string sql = "create table highscores (name varchar(20), score int)";
            string sql;

            sql = "CREATE TABLE 'src' ( `indext` INTEGER NOT NULL UNIQUE, `keyword` TEXT ( 50 ) NOT NULL UNIQUE," +
                  " `keywordfreq` INTEGER NOT NULL, " +
                  "`freqpercentage` NUMERIC, `freqmargin` NUMERIC, PRIMARY KEY(`indext`) )";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE TABLE 'tgt' ( `indext` INTEGER NOT NULL UNIQUE, `keyword` TEXT ( 50 ) NOT NULL UNIQUE," +
                  " `keywordfreq` INTEGER NOT NULL, " +
                  "`freqpercentage` NUMERIC, `freqmargin` NUMERIC, PRIMARY KEY(`indext`) )";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE TABLE `srctgt` ( `indexsrc` INTEGER NOT NULL, `indextgt` INTEGER NOT NULL, `freq` INTEGER, PRIMARY KEY(`indexsrc`,`indextgt`) )";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE INDEX `idx_srctgt_src` ON `srctgt` ( `indexsrc` )";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE INDEX `idx_srctgt_tgt` ON `srctgt` ( `indextgt` )";
            command.CommandText = sql;
            command.ExecuteNonQuery();

            sql = "CREATE INDEX `idx_src_keyword` ON `src` ( `keyword` )";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE INDEX `idx_tgt_keyword` ON `tgt` ( `keyword` )";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE TABLE `srccand` ( " +
                  "	`indexsrc`	NUMERIC NOT NULL, "+
                  "	`indextgt`	NUMERIC NOT NULL, "+
                  "	`freqpercentagesample`	NUMERIC, "+
                  "	`freqmarginsample`	NUMERIC, "+
                  "	`populationsampleratio`	NUMERIC, " +
                  "	`freqinsample`	NUMERIC, "+
                  "	PRIMARY KEY(`indexsrc`,`indextgt`) " +
                  " );";
            command.CommandText = sql;
            command.ExecuteNonQuery();
            sql = "CREATE TABLE `tgtcand` ( " +
                  "	`indexsrc`	NUMERIC NOT NULL, "+
                  "	`indextgt`	NUMERIC NOT NULL, "+
                  "	`freqpercentagesample`	NUMERIC, "+
                  "	`freqmarginsample`	NUMERIC, "+
                  "	`populationsampleratio`	NUMERIC, " +
                  "	`freqinsample`	NUMERIC, "+
                  "	PRIMARY KEY(`indexsrc`,`indextgt`) " +
                  " );";
            command.CommandText = sql;
            command.ExecuteNonQuery();



            m_dbConnection.Close();


            return(true);
        }