本文整理汇总了C#中SQLiteConnection类的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection类的具体用法?C# SQLiteConnection怎么用?C# SQLiteConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SQLiteConnection类属于命名空间,在下文中一共展示了SQLiteConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Clear
public void Clear()
{
using (var c = new SQLiteConnection(platform, DbPath))
{
c.Execute("DELETE FROM BackgroundTrackItem");
}
}
开发者ID:robUx4,项目名称:vlc-winrt,代码行数:7,代码来源:BackgroundTrackDatabase.cs
示例2: GetDatabse
private static SQLiteConnection GetDatabse()
{
var connection = new SQLiteConnection(new SQLitePlatformWinRT(), DbPath);
// 创建 Person 模型对应的表,如果已存在,则忽略该操作。
connection.CreateTable<PostDetail>();
return connection;
}
开发者ID:startewho,项目名称:SLWeek,代码行数:7,代码来源:BookmarkDatabase.cs
示例3: ByteArrayWhere
public void ByteArrayWhere()
{
//Byte Arrays for comparisson
ByteArrayClass[] byteArrays = new ByteArrayClass[] {
new ByteArrayClass() { bytes = new byte[] { 1, 2, 3, 4, 250, 252, 253, 254, 255 } }, //Range check
new ByteArrayClass() { bytes = new byte[] { 0 } }, //null bytes need to be handled correctly
new ByteArrayClass() { bytes = new byte[] { 0, 0 } },
new ByteArrayClass() { bytes = new byte[] { 0, 1, 0 } },
new ByteArrayClass() { bytes = new byte[] { 1, 0, 1 } },
new ByteArrayClass() { bytes = new byte[] { } }, //Empty byte array should stay empty (and not become null)
new ByteArrayClass() { bytes = null } //Null should be supported
};
SQLiteConnection database = new SQLiteConnection(TestPath.GetTempFileName());
database.CreateTable<ByteArrayClass>();
byte[] criterion = new byte[] { 1, 0, 1 };
//Insert all of the ByteArrayClass
int id = 0;
foreach (ByteArrayClass b in byteArrays)
{
database.Insert(b);
if (b.bytes != null && criterion.SequenceEqual<byte>(b.bytes))
id = b.ID;
}
Assert.AreNotEqual(0, id, "An ID wasn't set");
//Get it back out
ByteArrayClass fetchedByteArray = database.Table<ByteArrayClass>().Where(x => x.bytes == criterion).First();
Assert.IsNotNull(fetchedByteArray);
//Check they are the same
Assert.AreEqual(id, fetchedByteArray.ID);
}
开发者ID:Banane9,项目名称:sqlite-net,代码行数:34,代码来源:ByteArrayTest.cs
示例4: LibraryService
public LibraryService(
SQLiteConnection sqLiteConnection,
IDispatcherUtility dispatcherUtility)
{
_sqLiteConnection = sqLiteConnection;
_dispatcherUtility = dispatcherUtility;
}
开发者ID:haroldma,项目名称:Audiotica,代码行数:7,代码来源:LibraryService.cs
示例5: MultipleResultSets
public void MultipleResultSets()
{
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
conn.Open();
conn.ExecuteNonQuery(@"create table Test(Id integer not null primary key autoincrement, Value text not null);");
conn.ExecuteNonQuery(@"insert into Test(Id, Value) values(1, 'one'), (2, 'two');");
using (var cmd = (SQLiteCommand) conn.CreateCommand())
{
cmd.CommandText = @"select Value from Test where Id = @First; select Value from Test where Id = @Second;";
cmd.Parameters.Add("First", DbType.Int64).Value = 1L;
cmd.Parameters.Add("Second", DbType.Int64).Value = 2L;
using (var reader = cmd.ExecuteReader())
{
Assert.IsTrue(reader.Read());
Assert.AreEqual("one", reader.GetString(0));
Assert.IsFalse(reader.Read());
Assert.IsTrue(reader.NextResult());
Assert.IsTrue(reader.Read());
Assert.AreEqual("two", reader.GetString(0));
Assert.IsFalse(reader.Read());
Assert.IsFalse(reader.NextResult());
}
}
}
}
开发者ID:sakurahoshi,项目名称:System.Data.SQLite,代码行数:31,代码来源:SqliteCommandTests.cs
示例6: AutoGuid_HasGuid
public void AutoGuid_HasGuid()
{
var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.GetTempFileName());
db.CreateTable<TestObj>(CreateFlags.AutoIncPK);
var guid1 = new Guid("36473164-C9E4-4CDF-B266-A0B287C85623");
var guid2 = new Guid("BC5C4C4A-CA57-4B61-8B53-9FD4673528B6");
var obj1 = new TestObj
{
Id = guid1,
Text = "First Guid Object"
};
var obj2 = new TestObj
{
Id = guid2,
Text = "Second Guid Object"
};
int numIn1 = db.Insert(obj1);
int numIn2 = db.Insert(obj2);
Assert.AreEqual(guid1, obj1.Id);
Assert.AreEqual(guid2, obj2.Id);
db.Close();
}
开发者ID:happynik,项目名称:SQLite.Net-PCL,代码行数:26,代码来源:GuidTests.cs
示例7: GetOptions
public static Options GetOptions()
{
using (SQLiteConnection conn = new SQLiteConnection(dbLocation))
{
return conn.Get<Options>(1);
}
}
开发者ID:spaceyjase,项目名称:timer,代码行数:7,代码来源:OptionsRepository.cs
示例8: SaveOptions
public static int SaveOptions(Options options)
{
using (SQLiteConnection conn = new SQLiteConnection(dbLocation))
{
return conn.Update(options);
}
}
开发者ID:spaceyjase,项目名称:timer,代码行数:7,代码来源:OptionsRepository.cs
示例9: SetSqlConnection
public static void SetSqlConnection(SQLiteConnection newConnection)
{
conn = newConnection;
var db = Container.Resolve<ICurrencyDatabase>();
db.Connection = conn;
db.RegisterTables();
}
开发者ID:nicwise,项目名称:codemania2014,代码行数:7,代码来源:App.cs
示例10: OptionsRepository
static OptionsRepository()
{
// Figure out where the SQLite database will be.
var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
dbLocation = Path.Combine(documents, "timer_sqlite-net.db");
using (SQLiteConnection conn = new SQLiteConnection(dbLocation))
{
conn.CreateTable<Options>();
Options o = null;
try
{
o = conn.Get<Options>(1);
}
catch (InvalidOperationException)
{
// Doesn't exist...
}
if (o == null)
{
// Create options... a bit contrived perhaps :)
o = new Options();
o.Seconds = 5;
int rows = conn.Insert(o);
if (rows == 0)
{
throw new InvalidOperationException("Can't create options!");
}
}
}
}
开发者ID:spaceyjase,项目名称:timer,代码行数:30,代码来源:OptionsRepository.cs
示例11: Install
public static void Install(SQLiteConnection connection, string schema)
{
if (connection == null) throw new ArgumentNullException("connection");
Log.Info("Start installing Hangfire SQL objects...");
var script = GetStringResource(
typeof(SQLiteObjectsInstaller).Assembly,
"Hangfire.SQLite.Install.sql");
script = script.Replace("SET @TARGET_SCHEMA_VERSION = 5;", "SET @TARGET_SCHEMA_VERSION = " + RequiredSchemaVersion + ";");
script = script.Replace("$(HangFireSchema)", !string.IsNullOrWhiteSpace(schema) ? schema : Constants.DefaultSchema);
for (var i = 0; i < RetryAttempts; i++)
{
try
{
connection.Execute(script);
break;
}
catch (SQLiteException ex)
{
throw;
}
}
Log.Info("Hangfire SQL objects installed.");
}
开发者ID:AGRocks,项目名称:HangfireExtension,代码行数:29,代码来源:SQLiteObjectsInstaller.cs
示例12: Invoke
public void Invoke(ServerMessage message, IIrcClient ircClient, ILogger logger)
{
if (message.Command.Equals("376") && !_isInitialized) //We use this to initialize the plugin. This should only happen once.
{
_ircClient = ircClient;
_logger = logger;
//Subscribe to when the stream startes/ends events
_ircClient.TwitchService.OnStreamOnline += TwitchService_OnStreamOnline;
_ircClient.TwitchService.OnStreamOffline += TwitchService_OnStreamOffline;
_timer.AutoReset = true;
_timer.Interval = 60000;
_timer.Elapsed += _timer_Elapsed;
_timer.Enabled = true;
_dataFolder = PluginHelper.GetPluginDataFolder(this);
_database = new SQLiteConnection(new SQLitePlatformWin32(), Path.Combine(_dataFolder, "CurrencyPlugin.db"));
_database.CreateTable<CurrencyUserModel>();
//This is for debugging
//_watchedChannelsList.Add("#unseriouspid");
//_onlineChannelsList.Add("#unseriouspid");
_logger.Write($"{GetType().Name} Initialized.");
_isInitialized = true;
}
else if (message.Command.Equals("PRIVMSG") &&
_isInitialized &&
_watchedChannelsList.Contains(message.GetChannelName()))
{
var userCommand = message.Trailing.Split(' ')[0].ToLower().TrimStart();
var nickName = message.GetSender();
var channelName = message.GetChannelName();
switch (userCommand)
{
case "!points":
if (IsUserCommandOnCooldown(userCommand, nickName, channelName)) return;
DisplayPoints(nickName, channelName);
CooldownUserCommand(userCommand, nickName, channelName);
break;
case "!gamble":
if (IsUserCommandOnCooldown(userCommand, nickName, channelName)) return;
DoGamble(message);
CooldownUserCommand(userCommand, nickName, channelName);
break;
case "!bonus":
DoAddBonus(message);
break;
case "!bonusall":
DoAddBonusAll(message);
break;
}
}
}
开发者ID:xxJohnxx,项目名称:DotDotBot,代码行数:60,代码来源:CurrencyPlugin.cs
示例13: DeleteItem
public string DeleteItem(int itemId)
{
string result = string.Empty;
using (var dbConn = new SQLiteConnection(App.SQLITE_PLATFORM, App.DB_PATH))
{
var existingItem = dbConn.Query<Media>("select * from Media where Id =" + itemId).FirstOrDefault();
if (existingItem != null)
{
dbConn.RunInTransaction(() =>
{
dbConn.Delete(existingItem);
if (dbConn.Delete(existingItem) > 0)
{
result = "Success";
}
else
{
result = "This item was not removed";
}
});
}
return result;
}
}
开发者ID:Kinani,项目名称:TimelineMe-deprecated-,代码行数:27,代码来源:MediaViewModel.cs
示例14: GetSqlConnection
public SQLiteConnection GetSqlConnection(string fileName)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var plat=new SQLite.Net.Platform.WindowsPhone8.SQLitePlatformWP8();
var conn=new SQLiteConnection(plat, path);
return conn;
}
开发者ID:Asseks,项目名称:MultilangXamarinApp,代码行数:7,代码来源:SQLiteWinPhone.cs
示例15: ListAllBooks
private static void ListAllBooks(string connectionString)
{
SQLiteConnection databaseConnection = new SQLiteConnection(connectionString);
databaseConnection.Open();
using (databaseConnection)
{
string sqlStringCommand = "SELECT * FROM Books";
SQLiteCommand allBooks = new SQLiteCommand(sqlStringCommand, databaseConnection);
SQLiteDataReader reader = allBooks.ExecuteReader();
using (reader)
{
while (reader.Read())
{
Console.WriteLine(
"Title: {0}, \nAuthor: {1}, \nPublishDate: {2}, \nISBN: {3}",
reader["Title"],
reader["Author"],
(DateTime) reader["PublishDate"],
reader["ISBN"]);
Console.WriteLine();
}
}
}
}
开发者ID:iwelina-popova,项目名称:Databases,代码行数:26,代码来源:SQLiteStarup.cs
示例16: Startup
public static void Startup()
{
SQLiteConnection connection = null;
string dbLocation = "expensesDB.db3";
#if __ANDROID__
var library = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
dbLocation = Path.Combine(library, dbLocation);
var platform = new SQLitePlatformAndroid();
connection = new SQLiteConnection(platform, dbLocation);
#elif __IOS__
CurrentPlatform.Init();
var docsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var libraryPath = Path.Combine(docsPath, "../Library/");
dbLocation = Path.Combine(libraryPath, dbLocation);
var platform = new SQLitePlatformIOS();
connection = new SQLiteConnection(platform, dbLocation);
#elif WINDOWS_PHONE
var platform = new SQLitePlatformWP8();
dbLocation = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbLocation);
connection = new SQLiteConnection(platform, dbLocation);
#endif
ServiceContainer.Register<IMessageDialog>(() => new MessageDialog());
ServiceContainer.Register<ICloudService>(AzureService.Instance);
ServiceContainer.Register<IExpenseService>(() => new ExpenseService(connection));
ServiceContainer.Register<ExpensesViewModel>();
ServiceContainer.Register<ExpenseViewModel>();
}
开发者ID:Deerap,项目名称:MyExpenses-Xamarin,代码行数:30,代码来源:ServiceRegistrar.cs
示例17: UserService
public UserService(SQLiteConnection database, ILogger logger, string botOwner)
{
_database = database;
_database.CreateTable<UserDatabaseEntity>();
_logger = logger;
_botOwner = botOwner.ToLower();
}
开发者ID:notepid,项目名称:DotDotBot,代码行数:7,代码来源:UserService.cs
示例18: loadButton_Click
private void loadButton_Click(object sender, EventArgs e)
{
SQLiteConnection db = new SQLiteConnection(new SQLite.Net.Platform.Win32.SQLitePlatformWin32(), @"d:\dnd\dndspells.sqlite");
spells = db.Table<Spell>().ToList<Spell>();
populateList();
}
开发者ID:mostak,项目名称:dnd,代码行数:7,代码来源:Form1.cs
示例19: ByteArrays
public void ByteArrays()
{
//Byte Arrays for comparisson
ByteArrayClass[] byteArrays = new ByteArrayClass[] {
new ByteArrayClass() { bytes = new byte[] { 1, 2, 3, 4, 250, 252, 253, 254, 255 } }, //Range check
new ByteArrayClass() { bytes = new byte[] { 0 } }, //null bytes need to be handled correctly
new ByteArrayClass() { bytes = new byte[] { 0, 0 } },
new ByteArrayClass() { bytes = new byte[] { 0, 1, 0 } },
new ByteArrayClass() { bytes = new byte[] { 1, 0, 1 } },
new ByteArrayClass() { bytes = new byte[] { } }, //Empty byte array should stay empty (and not become null)
new ByteArrayClass() { bytes = null } //Null should be supported
};
SQLiteConnection database = new SQLiteConnection(TestPath.GetTempFileName());
database.CreateTable<ByteArrayClass>();
//Insert all of the ByteArrayClass
foreach (ByteArrayClass b in byteArrays)
database.Insert(b);
//Get them back out
ByteArrayClass[] fetchedByteArrays = database.Table<ByteArrayClass>().OrderBy(x => x.ID).ToArray();
Assert.AreEqual(fetchedByteArrays.Length, byteArrays.Length);
//Check they are the same
for (int i = 0; i < byteArrays.Length; i++)
{
byteArrays[i].AssertEquals(fetchedByteArrays[i]);
}
}
开发者ID:Banane9,项目名称:sqlite-net,代码行数:30,代码来源:ByteArrayTest.cs
示例20: CreateCommand
private PreparedSqlLiteInsertCommand CreateCommand(SQLiteConnection conn, string extra)
{
var cols = _tableMapping.InsertColumns;
string insertSql;
if (!cols.Any() && _tableMapping.Columns.Count() == 1 && _tableMapping.Columns[0].IsAutoInc)
{
insertSql = string.Format("insert {1} into \"{0}\" default values", _tableMapping.TableName, extra);
}
else
{
var replacing = string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0;
if (replacing)
{
cols = _tableMapping.Columns;
}
insertSql = string.Format("insert {3} into \"{0}\"({1}) values ({2})", _tableMapping.TableName,
string.Join(",", (from c in cols
select "\"" + c.Name + "\"").ToArray()),
string.Join(",", (from c in cols
select "?").ToArray()), extra);
}
return new PreparedSqlLiteInsertCommand(conn)
{
CommandText = insertSql
};
}
开发者ID:Reza1024,项目名称:SQLite.Net-PCL,代码行数:29,代码来源:ActiveInsertCommand.cs
注:本文中的SQLiteConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论