本文整理汇总了C#中Mono.Data.Sqlite.SqliteConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.Close方法的具体用法?C# SqliteConnection.Close怎么用?C# SqliteConnection.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDatabase
public virtual bool CreateDatabase( string sFile, bool bKeepOpen = false )
{
myDatabase = new SqliteConnection();
try {
if( System.IO.File.Exists(sFile) ) {
if( bKeepOpen == true ) {
myDatabase.ConnectionString = "Data Source=" + sFile + ";";
myDatabase.Open();
}
return false;
}
myDatabase.ConnectionString = "Data Source=" + sFile + ";";
myDatabase.Open();
if( bKeepOpen == false ) {
myDatabase.Close();
myDatabase.Dispose();
}
return true;
} catch {
return false;
}
}
示例2: CreateDataBase
public void CreateDataBase(string dbPath, string pwd)
{
if (!File.Exists(dbPath))
{
SqliteConnection.CreateFile(dbPath);
if (string.IsNullOrEmpty(pwd))
{
using (SqliteConnection conn = new SqliteConnection("Data Source=" + dbPath))
{
try
{
conn.SetPassword(pwd);
}
catch
{
conn.Close();
throw;
}
finally
{
conn.Close();
}
}
}
}
else
throw new Exception("已经存在名叫:" + dbPath + "的数据库!");
}
示例3: DataStore
public DataStore()
{
#if WHACKDB
File.Delete("GSharp.db3");
#endif
SqliteConnection conn;
if ( !File.Exists("GSharp.db3"))
{
SqliteConnection.CreateFile("GSharp.db3");
using ( conn = new SqliteConnection ("DbLinqProvider=Sqlite;Data Source=GSharp.db3") )
{
var s = Assembly.GetExecutingAssembly().GetManifestResourceStream("GSharp.Data.GSharp.sql");
var sr = new StreamReader(s);
using ( var cmd = conn.CreateCommand() )
{
cmd.CommandText = sr.ReadToEnd();
cmd.CommandType = CommandType.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
conn = new SqliteConnection ("DbLinqProvider=Sqlite;Data Source=GSharp.db3");
database = new Main (conn);
}
示例4: StepEntryDatabase
public StepEntryDatabase (string dbPath)
{
var output = "";
path = dbPath;
// create the tables
bool exists = File.Exists (dbPath);
if (!exists) {
using (connection = new SqliteConnection ("Data Source=" + dbPath)) {
connection.Open ();
var commands = new[] {
"CREATE TABLE [Items] (_id INTEGER PRIMARY KEY ASC, Steps BIGINT, Date NTEXT);"
};
foreach (var command in commands) {
using (var c = connection.CreateCommand ()) {
c.CommandText = command;
var i = c.ExecuteNonQuery ();
}
}
connection.Close ();
}
} else {
// already exists, do nothing.
}
Console.WriteLine (output);
}
示例5: GetConnection
public static SqliteConnection GetConnection()
{
var documents = Environment.GetFolderPath (
Environment.SpecialFolder.Personal);
string db = Path.Combine (documents, dbName);
bool exists = File.Exists (db);
if (!exists)
SqliteConnection.CreateFile (db);
var conn = new SqliteConnection ("Data Source=" + db);
if (!exists) {
var commands = new[] {
"CREATE TABLE Movie (Id INTEGER NOT NULL, Title ntext, Rating ntext, DateCreated datetime)",
"INSERT INTO Movie (Id, Title, Rating, DateCreated) VALUES (1, 'Traffic', 'R', '2007-01-01 10:00:00')",
"INSERT INTO Movie (Id, Title, Rating, DateCreated) VALUES (2, 'The Breakfast Club', 'R', '2007-01-01 10:00:00')",
};
foreach (var cmd in commands) {
using (var c = conn.CreateCommand()) {
c.CommandText = cmd;
c.CommandType = CommandType.Text;
conn.Open ();
c.ExecuteNonQuery ();
conn.Close ();
}
}
}
return conn;
}
示例6: LoadHistory_DB
public List<dateData> LoadHistory_DB(Quote q)
{
List<dateData> dataList = new List<dateData>();
string tblNm = GetTableNameHistory_DB(q);
if (!TableExist(tblNm))
return dataList;
SqliteConnection conn = null;
string sql = "";
try {
conn = new SqliteConnection(souce);
conn.Open();
SqliteCommand cmd = conn.CreateCommand();
sql = "select date, volume, open, high, low, close from " + tblNm + " order by date desc;";
cmd.CommandText = sql;
SqliteDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) {
dateData dd = new dateData();
dd._date = rdr.GetInt64(0);
dd._indic._volume = rdr.GetInt64(1);
dd._price._open = rdr.GetDouble(2);
dd._price._high = rdr.GetDouble(3);
dd._price._low = rdr.GetDouble(4);
dd._price._close = rdr.GetDouble(5);
dataList.Add(dd);
}
} catch (Exception e) {
Output.LogException(" sql (" + sql + ") error : " + e.Message);
}
if (conn != null)
conn.Close();
return dataList;
}
示例7: LoadQuotesInfo_DB
/// <summary>
/// Loads all empty quotes.
/// </summary>
/// <returns>
/// The all quotes only have basic information like code.
/// </returns>
public List<Quote> LoadQuotesInfo_DB()
{
List<Quote> allQ = new List<Quote>();
SqliteConnection conn = null;
string sql = "";
try {
conn = new SqliteConnection(souce);
conn.Open();
SqliteCommand cmd = conn.CreateCommand();
sql = "select si_market, si_code, si_name from " + TableNameInfo + ";";
cmd.CommandText = sql;
SqliteDataReader rdr = cmd.ExecuteReader();
information info = information.EMPTY;
int count = 0;
while (rdr.Read()) {
info._market._value = (market.type)rdr.GetInt32(0);
info.CodeInt = rdr.GetInt32(1);
info._name = rdr.GetString(2);
Quote q = new Quote(info);
allQ.Add(q);
Output.Log("" + ++count + " quotes loaded - " + q.Describe);
}
} catch (Exception e) {
Output.LogException("sql(" + sql + ") error : " + e.Message);
}
if (conn != null)
conn.Close();
return allQ;
}
示例8: SaveUserTest
public void SaveUserTest()
{
var sut = new UserPersister();
var user = new User { Email = "[email protected]", FirstName = "Louis",
LastName = "Salin", Password = "pass123" };
sut.Save(user);
using (var connection = new SqliteConnection("URI=file:Users.db3"))
{
var query = "SELECT * FROM Users WHERE Email='[email protected]';";
using (var cmd = connection.CreateCommand())
{
connection.Open();
cmd.CommandText = query;
using (var reader = cmd.ExecuteReader())
{
reader.Read();
reader["FirstName"].ShouldEqual("Louis");
reader["LastName"].ShouldEqual("Salin");
reader["Email"].ShouldEqual("[email protected]");
reader["Password"].ShouldEqual("pass123");
reader.Close();
}
connection.Close();
}
}
}
示例9: GetConnection
public static SqliteConnection GetConnection()
{
var documents = Environment.GetFolderPath (
Environment.SpecialFolder.Personal);
string db = Path.Combine (documents, "mydb.db3");
bool exists = File.Exists (db);
if (!exists)
SqliteConnection.CreateFile (db);
var conn = new SqliteConnection ("Data Source=" + db);
if (!exists) {
var commands = new[] {
"CREATE TABLE People (Id INTEGER NOT NULL, FirstName ntext, LastName ntext, DateCreated datetime)",
"INSERT INTO People (Id, FirstName, LastName, DateCreated) VALUES (1, 'Homer', 'Simpson', '2007-01-01 10:00:00')",
};
foreach (var cmd in commands){
using (var c = conn.CreateCommand()) {
c.CommandText = cmd;
c.CommandType = CommandType.Text;
conn.Open ();
c.ExecuteNonQuery ();
conn.Close ();
}
}
}
return conn;
}
示例10: folios
//constructor
static folios()
{
try {
//conexion a DB
var connection = new SqliteConnection(dbSource);
connection.Open();
//crear query
var query = connection.CreateCommand();
query.CommandText = "select consecutivo from folios where fecha='" + fecha + "'";
//inicia en el folio de la DB
generarConsecutivo=Convert.ToInt16(query.ExecuteScalar());
//si el valor es 0, entonces creamos un nuevo renglon para ese dia
//esto del 0 no necesariamente funciona en VistaDB
if(generarConsecutivo.Equals(0))
{
generarConsecutivo=1;
query = connection.CreateCommand();
query.CommandText = "insert into folios (fecha,consecutivo) values ('" + fecha + "'," + generarConsecutivo.ToString() + ")";
query.ExecuteNonQuery();
}
//cerrar conexion a DB
connection.Close();
} catch(Exception ex) {
//en caso de error en la base de datos empezamos en 1
generarConsecutivo=1;
}
}
示例11: ExcuteTransaction
public bool ExcuteTransaction(string sql)
{
var cmds = sql.Split(';');
using (SqliteConnection conn = new SqliteConnection(this.SqlConfig.ConnectionString))
{
conn.Open();
SqliteCommand cmd = new SqliteCommand(conn);
SqliteTransaction tran = conn.BeginTransaction();
try
{
foreach (var cmdSql in cmds)
{
cmd.CommandText = cmdSql;
cmd.ExecuteNonQuery();
}
tran.Commit();
conn.Close();
return true;
}
catch (Exception e)
{
tran.Rollback();
conn.Close();
throw new Exception(e.Message + " sql:" + sql);
}
finally
{
conn.Close();
}
}
}
示例12: DeletePhrase
public int DeletePhrase(Phrase item)
{
int r = 0;
lock (locker) {
if (item.id != 0) {
var connection = new SqliteConnection ("Data Source=" + path);
connection.Open ();
using (var command = connection.CreateCommand ()) {
command.CommandText = "Select * from [Phrase] where [id] = ?";
command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.id });
var result = command.ExecuteReader ();
if (result.HasRows) {
command.Dispose ();
command.CommandText = "Delete from [Phrase] where [id] = ?";
command.Parameters.Add(new SqliteParameter (DbType.String) { Value = item.categoryId });
r = command.ExecuteNonQuery ();
}
connection.Close ();
}
}
}
return r;
}
示例13: Start
void Start ()
{
string connectionString = "URI=file:" + Application.dataPath + "/GameMaster"; //Path to database.
IDbConnection dbcon = new SqliteConnection(connectionString) as IDbConnection;
dbcon.Open(); //Open connection to the database.
IDbCommand dbcmd = dbcon.CreateCommand();
dbcmd.CommandText = "SELECT firstname, lastname " + "FROM addressbook";
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read())
{
string FirstName = reader.GetString (0);
string LastName = reader.GetString (1);
Console.WriteLine("Name: " + FirstName + " " + LastName);
UnityEngine.Debug.LogWarning("Name: " + FirstName + " " + LastName);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
示例14: proDataExc
public string proDataExc(string[] strTT)
{
try
{
if (strTT.Length < 1) { return "No SQL"; }
string DatabaseName = "PUB.db3";
string documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string db = System.IO.Path.Combine(documents, DatabaseName);
var conn = new SqliteConnection("Data Source=" + db);
var sqlitecmd = conn.CreateCommand();
conn.Open();
sqlitecmd.CommandType = CommandType.Text;
for (int j = 0; j < strTT.Length; j++)
{
if (strTT[j] == "") { continue; }
sqlitecmd.CommandText = strTT[j];
sqlitecmd.ExecuteNonQuery();
}
conn.Close();
conn.Dispose();
return "";
}
catch (Exception Ex)
{
return Ex.ToString();
}
}
示例15: ExecuteSQLQuery
// Выполняет запрос, и в случае если это был INSERT, возвратит rowid добавленной записи
private int ExecuteSQLQuery(string query, out int lastInsertedRowId)
{
using (var connection = new SqliteConnection($"Data Source={m_fileName}"))
{
connection.Open();
int rowCount;
using (var command = connection.CreateCommand())
{
command.CommandText = query;
rowCount = command.ExecuteNonQuery();
}
// Получаем rowid последней добавленной записи. Важно чтобы он был в пределах того же соединения
// что и INSERT запрос (который предположительно идет прямо перед этим), иначе всегда возвращается 0
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT last_insert_rowid();";
using (var reader = command.ExecuteReader())
{
Debug.Assert(reader.HasRows);
reader.Read();
lastInsertedRowId = reader.GetInt32(0);
}
}
connection.Close();
return rowCount;
}
}