Exemplo n.º 1
0
 static void CloseDB(ConEgg ce)
 {
     ce.SQLComm = new SQLiteCommand("end", ce.SQLiteCon);
     ce.SQLComm.ExecuteNonQuery();
     ce.SQLiteCon.Close();
     return;
 }
Exemplo n.º 2
0
        static bool AddRelations2DB(ConEgg ce, string[] wordssrc, string[] wordstgt)
        {
            string sqlsrcaux = "select indext from src where keyword='{0}'";
            string sqltgtaux = "select indext from tgt where keyword='{0}'";
            string sql;
            int    indexsrc, indextgt;
            object result = "";


            // create all relations
            foreach (string srcstring in wordssrc)
            {
                sql = string.Format(sqlsrcaux, srcstring);
                ce.SQLComm.CommandText = sql;
                indexsrc = Convert.ToInt32(ce.SQLComm.ExecuteScalar());
                foreach (string tgtstring in wordstgt)
                {
                    sql = string.Format(sqltgtaux, tgtstring);
                    ce.SQLComm.CommandText = sql;
                    indextgt = Convert.ToInt32(ce.SQLComm.ExecuteScalar());
                    // have source and target first try to find out if the pair
                    // exists (update) otherwise insert
                    sql = string.Format("select freq from srctgt where indexsrc={0} and indextgt={1}",
                                        indexsrc, indextgt);
                    ce.SQLComm.CommandText = sql;
                    result = ce.SQLComm.ExecuteScalar();
                    if (ce.SQLComm.ExecuteScalar() != null)
                    {
                        // ya existe solo tengo que actualizar
                        //Console.Write(" ");
                        sql = string.Format("update srctgt set freq={0} where indexsrc={1} and indextgt={2}",
                                            Convert.ToInt32(result) + 1, indexsrc, indextgt);
                        ce.SQLComm.CommandText = sql;
                        ce.SQLComm.ExecuteNonQuery();
                    }
                    else
                    {
                        // Does not exist, we need and update
                        //Console.Write("+");
                        sql = "insert into srctgt (indexsrc,indextgt,freq) values ({0},{1},1)";
                        sql = string.Format(sql, indexsrc, indextgt);
                        ce.SQLComm.CommandText = sql;
                        ce.SQLComm.ExecuteNonQuery();
                    }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        static bool AddKey2DB(ConEgg ce, string keyword, string table)
        {
            object result = "";

            string sql = string.Format("select indext from {0} where keyword='{1}'",
                                       table, keyword);

            ce.SQLComm.CommandText = sql;
            result = ce.SQLComm.ExecuteScalar();
            if (ce.SQLComm.ExecuteScalar() != null)
            {
                // ya existe solo tengo que actualizar
                int keywordfreq;
                sql = string.Format("select keywordfreq from {0} where indext={1}", table, result);
                // somethin like select keywordfreq from SRC where indexSRC=1234", table, result);
                ce.SQLComm.CommandText = sql;
                keywordfreq            = Convert.ToInt32(ce.SQLComm.ExecuteScalar()) + 1;

                //Console.Write(" ");
                sql = string.Format("update {0} set keywordfreq={1} where indext={2}",
                                    table, keywordfreq, result);
                ce.SQLComm.CommandText = sql;
                ce.SQLComm.ExecuteNonQuery();
            }
            else
            {
                // Does not exist, we need and update
                //Console.Write("-");
                sql = "insert into {0} (keyword,keywordfreq) values ('{1}',1)";
                sql = string.Format(sql, table, keyword);
                ce.SQLComm.CommandText = sql;
                ce.SQLComm.ExecuteNonQuery();
            }


            return(true);
        }