当前位置: 首页>>代码示例>>C#>>正文


C# SQLiteConnection.Prepare方法代码示例

本文整理汇总了C#中SQLitePCL.SQLiteConnection.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Prepare方法的具体用法?C# SQLiteConnection.Prepare怎么用?C# SQLiteConnection.Prepare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLitePCL.SQLiteConnection的用法示例。


在下文中一共展示了SQLiteConnection.Prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadDatabase

        public static void LoadDatabase(SQLiteConnection db)
        {
            string sql = @"CREATE TABLE IF NOT EXISTS
                                Customer (Id      INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
                                            Name    VARCHAR( 140 ),
                                            City    VARCHAR( 140 ),
                                            Contact VARCHAR( 140 ) 
                            );";
            using (var statement = db.Prepare(sql))
            {
                statement.Step();
            }

            sql = @"CREATE TABLE IF NOT EXISTS
                                Project (Id          INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
                                         CustomerId  INTEGER,
                                         Name        VARCHAR( 140 ),
                                         Description VARCHAR( 140 ),
                                         DueDate     DATETIME,
                                         FOREIGN KEY(CustomerId) REFERENCES Customer(Id) ON DELETE CASCADE 
                            )";
            using (var statement = db.Prepare(sql))
            {
                statement.Step();
            }

            // Turn on Foreign Key constraints
            sql = @"PRAGMA foreign_keys = ON";
            using (var statement = db.Prepare(sql))
            {
                statement.Step();
            }
        }
开发者ID:MuffPotter,项目名称:201505-MVA,代码行数:33,代码来源:CreateDatabase.cs

示例2: EnableForeignKeys

		private void EnableForeignKeys(SQLiteConnection connection)
		{
			using (var statement = connection.Prepare(@"PRAGMA foreign_keys = ON;"))
			{
				statement.Step();
			}
		}
开发者ID:valeronm,项目名称:handyNews,代码行数:7,代码来源:LocalStorageManager.cs

示例3: getDownloads

        public static ObservableCollection<Downloads> getDownloads()
        {
            string path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "User.db");

            ObservableCollection<Downloads> list = new ObservableCollection<Downloads>();

            using (var connection = new SQLiteConnection(path))
            {
                using (var statement = connection.Prepare(@"SELECT * FROM DownloadList;"))
                {

                    while (statement.Step() == SQLiteResult.ROW)
                    {

                        list.Add(new Downloads()
                        {
                            FileName = (string)statement[0],
                            Path = (string)statement[1],
                            Date = (string)statement[2],
                            Size = (string)statement[3]

                          
                        });

                        Debug.WriteLine(statement[0] + " ---" + statement[1] + " ---" + statement[2]);
                    }
                }
            }
            return list;
        }
开发者ID:mtwn105,项目名称:PDFMe-Windows-10,代码行数:30,代码来源:DatabaseController.cs

示例4: AddDownload

        public static void AddDownload(string filename,string path, string date, string size)
        {
            string path1 = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "User.db");

            try
            {
                using (var connection = new SQLiteConnection(path1))
                {
                    using (var statement = connection.Prepare(@"INSERT INTO DownloadList (FILENAME,PATH,DATE,SIZE)
                                    VALUES(?,?,?,?);"))
                    {
                       
                        statement.Bind(1, filename);
                        statement.Bind(2, path);
                        statement.Bind(3, date);
                        statement.Bind(4, size);
                    
                        // Inserts data.
                        statement.Step();
                       
                        statement.Reset();
                        statement.ClearBindings();
                        Debug.WriteLine("Download Added");
                    }
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception\n" + ex.ToString());
            }
        }
开发者ID:mtwn105,项目名称:PDFMe-Windows-10,代码行数:32,代码来源:DatabaseController.cs

示例5: SqliteInitializationTest

        public void SqliteInitializationTest()
        {
            string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME);

            using (SQLiteLocalStorage storage = new SQLiteLocalStorage())
            { }

            using (SQLiteConnection connection = new SQLiteConnection(dbPath))
            {

                var query = "SELECT name FROM sqlite_master WHERE type='table'";
                var tableName = new List<string>();

                using (var sqliteStatement = connection.Prepare(query))
                {
                    while(sqliteStatement.Step() == SQLiteResult.ROW)
                    {
                        tableName.Add(sqliteStatement.GetText(0));
                    }
                }

                Assert.IsTrue(tableName.Count == 2);
                Assert.IsTrue(tableName.Contains("datasets"));
                Assert.IsTrue(tableName.Contains("records")); 
            }
        }
开发者ID:lawandeneel,项目名称:Fashion,代码行数:26,代码来源:SQLiteLocalStorageTests.cs

示例6: insertData

        public static void insertData(string param1, string param2, string param3)
        {
            try 
            { 
            using (var connection = new SQLiteConnection("Storage.db"))
            {
                using (var statement = connection.Prepare(@"INSERT INTO Student (ID,NAME,CGPA)
                                            VALUES(?, ?,?);"))
                {
                    statement.Bind(1, param1);
                    statement.Bind(2, param2);
                    statement.Bind(3, param3);

                    // Inserts data.
                    statement.Step();

                  
                    statement.Reset();
                    statement.ClearBindings();


                }
            }

            }
            catch(Exception ex)
            {
                Debug.WriteLine("Exception\n"+ex.ToString());
            }
        }
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:30,代码来源:DataBaseController.cs

示例7: getValues

        public static ObservableCollection<Student> getValues()
        {
             ObservableCollection<Student> list = new ObservableCollection<Student>();

            using (var connection = new SQLiteConnection("Storage.db"))
            {
                using (var statement = connection.Prepare(@"SELECT * FROM Student;"))
                {
                    
                    while (statement.Step() == SQLiteResult.ROW)
                    {
 
                        list.Add(new Student()
                        {
                            Id = (string)statement[0],
                            Name = (string)statement[1],
                            Cgpa = statement[2].ToString()
                        });

                        Debug.WriteLine(statement[0]+" ---"+statement[1]+" ---"+statement[2]);
                    }
                }
            }
            return list;
        }
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:25,代码来源:DataBaseController.cs

示例8: WordListDB

 public WordListDB()
 {
     connection_ = new SQLiteConnection(DB_NAME);
     using (var statement = connection_.Prepare(SQL_CREATE_TABLE))
     {
         statement.Step();
     }
 }
开发者ID:ZYY1995,项目名称:Database-OF,代码行数:8,代码来源:WordListDB.cs

示例9: PlanetaDao

 public PlanetaDao(SQLiteConnection con)
 {
     this.con = con;
     string sql = "CREATE TABLE IF NOT EXISTS planeta (id INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, gravedad FLOAT)";
     using (var statement =con.Prepare(sql)) {
         statement.Step();
     }
 }
开发者ID:milo2005,项目名称:W10_Persistencia,代码行数:8,代码来源:PlanetaDao.cs

示例10: FacturaDao

 public FacturaDao(SQLiteConnection con)
 {
     this.con = con;
     string sql = "CREATE TABLE IF NOT EXISTS factura (id INTEGER PRIMARY KEY AUTOINCREMENT, nombre TEXT, vence DATETIME, alarma DATETIME, valor INTEGER, estado TEXT)";
     using (var statement = con.Prepare(sql))
     {
         statement.Step();
     }
 }
开发者ID:dapintounicauca,项目名称:AppFacturas,代码行数:9,代码来源:FacturaDao.cs

示例11: Cleaup

        public void Cleaup()
        {
            string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME);

            //drop all the tables from the db
            using (SQLiteConnection connection = new SQLiteConnection(dbPath))
            {
                using (var sqliteStatement = connection.Prepare("DROP TABLE IF EXISTS records"))
                {
                    var result = sqliteStatement.Step();
                }

                using (var sqliteStatement = connection.Prepare("DROP TABLE IF EXISTS datasets"))
                {
                    var result = sqliteStatement.Step();
                }
            }
        }
开发者ID:lawandeneel,项目名称:Fashion,代码行数:18,代码来源:SQLiteLocalStorageTests.cs

示例12: ResetDataAsync

        /// <summary>
        /// Metoda czyszcząca bazę danych ze wszystkich informacji.
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
            public async static Task ResetDataAsync(SQLiteConnection db)
            {
                // Empty the Device and Comment tables 
                string sql = @"DELETE FROM Device";
                using (var statement = db.Prepare(sql))
                {
                    statement.Step();
                }

                sql = @"DELETE FROM Comment";
                using (var statement = db.Prepare(sql))
                {
                    statement.Step();
                }


           
        }
开发者ID:pkozak2,项目名称:CeneoETL-Projekt,代码行数:23,代码来源:CreateDatabase.cs

示例13: WordBookDB

 public WordBookDB()
 {
     mutex_ = new object();
     connection_ = new SQLiteConnection(SQL_CREATE_TABLE);
     using (var statement = connection_.Prepare(SQL_CREATE_TABLE))
     {
         statement.Step();
     }
 }
开发者ID:ZYY1995,项目名称:Database-OF,代码行数:9,代码来源:WordBookDB.cs

示例14: OnNavigatedTo

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                conn = App.conn;
                string req = @"Create Table if not exists  
                                                User (Id integer primary key autoincrement not null,
                                                      Login varchar(50),
                                                      Passeword varchar(50)
                                                      )";
                using (var Statement = conn.Prepare(req))
                {
                    Statement.Step();
                }

                req = @"select Login from User where Login='Admin'";
                using (var Statement = conn.Prepare(req))
                {
                    //if (SQLiteResult.DONE == Statement.Step())
                    //{
                        Statement.Step();
                        if (Statement.DataCount == 0)
                        {
                            req = @"insert into User(Login,Passeword) values('Admin','Admin')";
                            using (var Statement1 = conn.Prepare(req))
                            {
                                Statement1.Step();
                            }
                        }
                    //}
                }

              
            }
            catch (Exception ex)
            {
                MessageDialog Msg = new MessageDialog(ex.ToString());
                await Msg.ShowAsync();

            }
        }
开发者ID:Khoubaib1,项目名称:MyProducts,代码行数:46,代码来源:MainPage.xaml.cs

示例15: LoadDatabase

        public static void LoadDatabase()
        {
            // Get a reference to the SQLite database
            conn = new SQLiteConnection("SQLiteTODO.db");

            // NOTE - The Id character is actually a GUID which is 36 characters long.
            // Here we speacify it as VARCHAR(36) - but actually SQLite does not impose a length
            // limit on columns, nor rigidly enforce data types. 
            // Could have specified CHARACTER(10), VARCHAR(255), TEXT - all would work for a GUID.
            // SQLite just stores these as 'TEXT' - see http://www.sqlite.org/datatype3.html#expraff
            string sql = @"CREATE TABLE IF NOT EXISTS
                                ToDoList (Id      VARCHAR( 36 ) PRIMARY KEY NOT NULL,
                                          Title   VARCHAR( 140 ) 
                            );";
            using (var statement = conn.Prepare(sql))
            {
                statement.Step();
            }

            sql = @"CREATE TABLE IF NOT EXISTS
                                ToDoItem (Id         VARCHAR( 36 ) PRIMARY KEY NOT NULL,
                                         Title       VARCHAR( 140 ),
                                         DueDate     DATETIME,
                                         Details     VARCHAR( 140 ),
                                         IsFavorite  BOOLEAN,
                                         IsComplete  BOOLEAN,
                                         ListId      CHAR( 36 ),
                                         FOREIGN KEY(ListId) REFERENCES ToDoList(Id) ON DELETE CASCADE 
                            )";
            using (var statement = conn.Prepare(sql))
            {
                statement.Step();
            }

            // Turn on Foreign Key constraints
            sql = @"PRAGMA foreign_keys = ON";
            using (var statement = conn.Prepare(sql))
            {
                statement.Step();
            }
        }
开发者ID:MuffPotter,项目名称:201505-MVA,代码行数:41,代码来源:SQLiteService.cs


注:本文中的SQLitePCL.SQLiteConnection.Prepare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。