Exemplo n.º 1
0
        public static void CreateTable()
        {
            string dbPath = testDatabaseName;

            //如果不存在改数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB(testDatabaseName);
            }

            bool tableExist = false;

            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath))
            {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = "select count(*) from sqlite_master where type = 'table' and name = 'Test3'";
                    int num = Convert.ToInt32(command.ExecuteScalar());
                    if (num > 0)
                    {
                        tableExist = true;
                    }
                }
            }

            if (!tableExist)
            {
                SQLiteDBHelper db  = new SQLiteDBHelper(testDatabaseName);
                string         sql = "CREATE TABLE Test3(id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name char(3),TypeName varchar(50),addDate datetime,UpdateTime Date,Time time,Comments blob)";
                db.ExecuteNonQuery(sql, null);
            }
        }
Exemplo n.º 2
0
        static public bool SentToDB()
        {
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB(dbPath);
            }

            bool tableExist = false;

            using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath))
            {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand(connection))
                {
                    command.CommandText = "select count(*) from sqlite_master where type = 'table' and name = '" + existFilessName + "'";
                    int num = Convert.ToInt32(command.ExecuteScalar());
                    if (num > 0)
                    {
                        tableExist = true;
                    }
                }
            }

            SQLiteDBHelper db  = null;
            string         sql = null;

            if (tableExist)
            {
                db  = new SQLiteDBHelper(dbPath);
                sql = "DROP TABLE " + existFilessName;
                db.ExecuteNonQuery(sql, null);
            }

            db = new SQLiteDBHelper(dbPath);

            sql = "CREATE TABLE " + existFilessName + @"(
                    name  TEXT,         
                    filePath   TEXT )";
            db.ExecuteNonQuery(sql, null);

            sql = "INSERT INTO " + existFilessName + "(name,filePath)values(@name, @filePath)";
            db  = new SQLiteDBHelper(dbPath);
            for (int i = 0; i < g_FileInfoCollector.Count; i++)
            {
                SQLiteParameter[] parameters = new SQLiteParameter[] {
                    new SQLiteParameter("@name", ((FileInformation)g_FileInfoCollector[i]).FileName),
                    new SQLiteParameter("@filePath", ((FileInformation)g_FileInfoCollector[i]).FullName)
                };
                db.ExecuteNonQuery(sql, parameters);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static void InsertData()
        {
            string         sql = "INSERT INTO Test3(Name,TypeName,addDate,UpdateTime,Time,Comments)values(@Name,@TypeName,@addDate,@UpdateTime,@Time,@Comments)";
            SQLiteDBHelper db  = new SQLiteDBHelper(testDatabaseName);

            for (char c = 'A'; c <= 'Z'; c++)
            {
                for (int i = 0; i < 5; i++)
                {
                    SQLiteParameter[] parameters = new SQLiteParameter[] {
                        new SQLiteParameter("@Name", c + i.ToString()),
                        new SQLiteParameter("@TypeName", c.ToString()),
                        new SQLiteParameter("@addDate", DateTime.Now),
                        new SQLiteParameter("@UpdateTime", DateTime.Now.Date),
                        new SQLiteParameter("@Time", DateTime.Now.ToShortTimeString()),
                        new SQLiteParameter("@Comments", "Just a Test" + i)
                    };
                    db.ExecuteNonQuery(sql, parameters);
                }
            }
        }
Exemplo n.º 4
0
        protected override bool CreateTable()
        {
            try
            {
                SQLiteDBHelper db  = null;
                string         sql = null;

                db = new SQLiteDBHelper(datebaseName);

                if (db.IsTableExist(tableName))
                {
                    db.DeleteTable(tableName);
                }

                sql = @"CREATE TABLE file_name(
                    name  TEXT,
                    property1  TEXT,
                    property2  TEXT,
                    property3  TEXT,
                    property4  TEXT,
                    property5  TEXT,
                    property6  TEXT,
                    property7  TEXT,
                    property8  TEXT,
                    property9  TEXT,
                    property10 TEXT)";
                db.ExecuteNonQuery(sql, null);
            }
            catch (Exception)
            {
                return(false);
            }


            return(true);
        }