system.data.sqlite

System.Data.SQLite BackupDatabase() throws “not an error”

牧云@^-^@ 提交于 2019-12-06 11:32:41
I'm using System.Data.SQLite (version 1.0.85.0) to connect with my SQLite database. I want to create backup of the database using SQLiteConnection.BackupDatabase() method, however it throws SQLiteException with message:"not an error" (repeated twice). Here is some code: SQLiteConnection cnnIn = new SQLiteConnection("Data Source=test.db;foreign keys=True"); SQLiteConnection cnnOut = new SQLiteConnection("Data Source=backup.db;foreign keys=True"); cnnIn.Open(); cnnOut.Open(); cnnIn.BackupDatabase(cnnOut, "backup", "test", -1, null, -1); cnnIn.Close(); cnnOut.Close(); The error comes from System

How to escape a string in system.data.sqlite?

怎甘沉沦 提交于 2019-12-06 05:13:31
I am executing an SQL query (system.data.SQLite) like so: var color = "red"; var command = new SQLiteCommand("SELECT something FROM tabletop WHERE color = '" + color + "'", Connection); var reader = command.ExecuteReader(); The color variable is a text supplied by the user. How can I escape this text to prevent SQL injection? Or is this bad practice and I should execute the query in some entirely different "protected" way? You should use parameterized queries: var command = new SQLiteCommand("SELECT something FROM tabletop WHERE color = @Color", Connection); command.Parameters.AddWithValue(

Creating database using DataContext and System.Data.SQLite in C#

我与影子孤独终老i 提交于 2019-12-06 00:26:28
I'm writing simple application gathering information about machine's hardware. I plan to store data in sqlite. Got following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SQLite; using System.IO; using System.Data; using System.Data.Linq; using System.Data.Linq.Mapping; namespace SQLiteTest { public class MyDB : DataContext { public Table<Computer> kompy; public MyDB(string connection) : base(connection) { } public MyDB(IDbConnection connection) : base(connection) { } } [Table] public class Computer { [Column(IsPrimaryKey = true,

SQLite error when accessing first element in table using LINQ

拈花ヽ惹草 提交于 2019-12-05 21:25:12
I'm having the following issue when accessing a SQLite database using LINQ. Abreviated code looks like this: ... using System.Linq using System.Data.Linq using System.Data.Linq.Mapping using System.Data.SQLite ... DataContext sqltContext= new DataContext(sqltConnection); featureTable = sqltContext.GetTable<FeatureModel>(); count= featureTable.Count(); // count == 1 The following line fails with error: "SQL logic error or missing database\r\nunknown error" //currentFeature = featureTable.First(); But iterator works fine: foreach (var feature in featureTable) { currentFeature = feature; break; }

Identity column maximum value in SQLite DBs

自闭症网瘾萝莉.ら 提交于 2019-12-05 18:54:22
问题 I have a purely academic question about SQLite databases. I am using SQLite.net to use a database in my WinForm project, and as I was setting up a new table, I got to thinking about the maximum values of an ID column. I use the IDENTITY for my [ID] column, which according to SQLite.net DataType Mappings, is equivalent to DbType.Int64 . I normally start my ID columns at zero (with that row as a test record) and have the database auto-increment. The maximum value ( Int64.MaxValue ) is 9,223,372

XamarinSQLite教程Xamarin.Android项目添加引用

北城以北 提交于 2019-12-05 16:36:43
XamarinSQLite教程Xamarin.Android项目添加引用 在Xamarin.Android项目中,导入System.Data和Mono.Data.SQLite库的操作步骤如下: (1)打开Xamarin. Android项目,如AndroidSQLiteDemo项目。 (2)右击“引用”分支,单击“添加引用(R)…”命令,弹出“引用管理器”。 (3)选择System.Data和System.Data.SQLite库。单击“确定”按钮,此时这两个库就添加到了项目的引用中。 来源: oschina 链接: https://my.oschina.net/u/1585857/blog/1844488

INSERT with transaction and parameters?

☆樱花仙子☆ 提交于 2019-12-05 16:31:50
I'm learning about VB.Net and need to work with an SQLite database using the open-source System.Data.SQLite ADO.Net solution The examples I found in the HOWTO section are only in C#. Would someone have a simple example in VB.Net that I could study to understand how to use transactions when INSERTing multiple parameters? FWIW, here's the code I'm working on: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SQLconnect As New SQLite.SQLiteConnection() Dim SQLcommand As SQLite.SQLiteCommand Dim SQLtransaction As SQLite

Difficulty running concurrent INSERTS on SQLite database in C#

孤街浪徒 提交于 2019-12-05 15:41:15
I'm running a number of threads which each attempt to perform INSERTS to one SQLite database. Each thread creates it's own connection to the DB. They each create a command, open a Transaction perform some INSERTS and then close the transaction. It seems that the second thread to attempt anything gets the following SQLiteException: The database file is locked. I have tried unwrapping the INSERTS from the transaction as well as narrowing the scope of INSERTS contained within each commit with no real effect; subsequent access to the db file raises the same exception. Any thoughts? I'm stumped and

System.Data.Sqlite and FTS4

孤街浪徒 提交于 2019-12-05 05:18:17
问题 Why when i write a query with fulltext Search syntax like: SELECT * FROM TABLENAME WHERE TABLENAME MATCH 'ColumnA:word1 OR ColumnB:word2' The query result always return 0 rows? I'm using VBnet and the latest Ado.net provider from sqlite.org The problem is when i try the query with and external tool, it works well (with sqlite 3.7.9). Any clues? Thanks in advance 回答1: Although System.Data.Sqlite is compiled using SQLITE_ENABLE_FTS3 and supports FTS, it doesn't compiled with SQLITE_ENABLE_FTS3

How to enable foreign key cascade delete by default in SQLite?

点点圈 提交于 2019-12-05 04:51:45
SQLite v3.7.5 Is there a way to enable SQLite Foreign Keys with cascade delete enabled by default? Given the following example: CREATE TABLE [Parent] ( [ParentId] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [Name] VARCHAR(50) UNIQUE NOT NULL ); CREATE TABLE [Child] ( [ChildId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, [ParentId] INTEGER NOT NULL, [Name] VARCHAR(50) NOT NULL, FOREIGN KEY(ChildId) REFERENCES Child(ParentId) ON DELETE CASCADE ); The only way I've been able to enable the cascade delete is to execute the PRAGMA foreign_keys = true command before a transaction: using( var conn =