Example #1
0
        public static void TestSqlite()
        {
            string dbPath        = "f:\\testdb.sqlite";
            string connectString = "Data Source=f:\\testdb.sqlite;Pooling=true;FailIfMissing=false;";

            if (File.Exists(dbPath))
            {
                File.Delete(dbPath);
            }
            SqlDbContext db = new SQLiteDbContext(connectString);

            //SmartDb框架提供一个记录日志委托用来记录执行SQL及参数信息,ConsoleWriteInfo在控制台输出,大家可以根据自己需要自己定义方法传给DbHelper.logAction会自动进行调用
            db.DbHelper.logAction = db.DbHelper.ConsoleWriteInfo;

            var sql = "create  table UserInfo(UserId int not null,UserName  varchar(50),Age int,Email varchar(50))";

            db.ExecuteNoneQuery(sql, null);

            var dbTest = new DbTest(db);

            dbTest.DeleteAll();
            dbTest.Insert();
            dbTest.Delete();
            dbTest.Update();
            dbTest.Query();
            dbTest.OrtherQuery();
            dbTest.OrtherNoneQuery();
        }
Example #2
0
        public static void TestSqlite()
        {
            string dbPath        = "f:\\testdb.sqlite";
            string connectString = "Data Source=f:\\testdb.sqlite;Pooling=true;FailIfMissing=false;";

            if (File.Exists(dbPath))
            {
                File.Delete(dbPath);
            }
            SqlDbContext db = new SQLiteDbContext(connectString);

            //数据执行回调函数
            db.ExecuteDbCallBack = (cmdText, dbParms) => {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append("sql:" + cmdText);
                if (dbParms != null)
                {
                    foreach (IDbDataParameter param in dbParms)
                    {
                        stringBuilder.Append("paramName:" + param.ParameterName + ",paramValue:" + param.Value.ToString());
                    }
                }
                stringBuilder.Append("\n\n");
                Console.Write(stringBuilder.ToString());
            };

            //var sql = "create  table UserInfo(UserId int identity(1,1) primary key,UserName  varchar(50),Age int,Email varchar(50))";
            var sql = "create  table UserInfo(UserId int  primary key,UserName  varchar(50),Age int,Email varchar(50))";

            db.ExecuteNoneQuery(sql, null);

            var dbTest = new DbTest(db);

            dbTest.DeleteAll();
            dbTest.Insert();
            dbTest.Delete();
            dbTest.Update();
            dbTest.Query();
            dbTest.OrtherQuery();
            dbTest.OrtherNoneQuery();
        }