本文整理汇总了C#中Mono.Data.Sqlite.SqliteConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.Open方法的具体用法?C# SqliteConnection.Open怎么用?C# SqliteConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.Open方法的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: LoadAllPoliticans
public List<Politician> LoadAllPoliticans()
{
var politicians = new List<Politician> ();
using (var connection = new SqliteConnection (connectionString)) {
using (var cmd = connection.CreateCommand ()) {
connection.Open ();
cmd.CommandText = String.Format ("SELECT bioguide_id, first_name, last_name, govtrack_id, phone, party, state FROM Politician ORDER BY last_name");
using (var reader = cmd.ExecuteReader ()) {
while (reader.Read ()) {
politicians.Add (new Politician {
FirstName = reader ["first_name"].ToString (),
LastName = reader ["last_name"].ToString (),
BioGuideId = reader ["bioguide_id"].ToString (),
GovTrackId = reader ["govtrack_id"].ToString (),
Phone = reader ["phone"].ToString (),
State = reader ["state"].ToString (),
Party = reader ["party"].ToString ()
});
}
}
}
}
return politicians;
}
示例3: Init
public static void Init()
{
try
{
_cards = new Dictionary<int, CardData>();
string currentPath = Assembly.GetExecutingAssembly().Location;
currentPath = Path.GetDirectoryName(currentPath) ?? "";
string absolutePath = Path.Combine(currentPath, "cards.cdb");
if (!File.Exists(absolutePath))
{
throw new Exception("Could not find the cards database.");
}
using (SqliteConnection connection = new SqliteConnection("Data Source=" + absolutePath))
{
connection.Open();
const string select =
"SELECT datas.id, alias, type, level, race, attribute, atk, def, name, desc " +
"FROM datas INNER JOIN texts ON datas.id = texts.id";
using (SqliteCommand command = new SqliteCommand(select, connection))
using (SqliteDataReader reader = command.ExecuteReader())
InitCards(reader);
}
}
catch (Exception ex)
{
throw new Exception("Could not initialize the cards database. Check the inner exception for more details.", ex);
}
}
示例4: ClearItemsBeforeDate
/// <summary>
/// Clears all items from the database where their PublishDate is before the date provided.
/// </summary>
/// <param name="date"></param>
public void ClearItemsBeforeDate(DateTime date)
{
try
{
using (SqliteConnection connection = new SqliteConnection(ItemsConnectionString))
{
connection.Open();
using (SqliteCommand command = new SqliteCommand(connection))
{
string sql = @"DELETE FROM items WHERE DATETIME(publishdate) <= DATETIME(@date)";
command.CommandText = sql;
SqliteParameter parameter = new SqliteParameter("@date", DbType.String);
parameter.Value = date.ToString("yyyy-MM-dd HH:mm:ss");
command.Parameters.Add(parameter);
int rows = command.ExecuteNonQuery();
Logger.Info("ClearItemsBeforeDate before {0} cleared {1} rows.", date.ToString("yyyy-MM-dd HH:mm:ss"), rows);
}
}
}
catch (SqliteException e)
{
Logger.Warn("SqliteException occured while clearing items before {0}: \n{1}", date, e);
}
}
示例5: 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;
}
示例6: SQLiteMonoTransformationProvider
public SQLiteMonoTransformationProvider(Dialect dialect, string connectionString)
: base(dialect, connectionString)
{
_connection = new SqliteConnection(_connectionString);
_connection.ConnectionString = _connectionString;
_connection.Open();
}
示例7: Initialise
public void Initialise(string connectionString)
{
m_connectionString = connectionString;
m_log.Info("[ESTATE DB]: Sqlite - connecting: "+m_connectionString);
m_connection = new SqliteConnection(m_connectionString);
m_connection.Open();
Assembly assem = GetType().Assembly;
Migration m = new Migration(m_connection, assem, "EstateStore");
m.Update();
//m_connection.Close();
// m_connection.Open();
Type t = typeof(EstateSettings);
m_Fields = t.GetFields(BindingFlags.NonPublic |
BindingFlags.Instance |
BindingFlags.DeclaredOnly);
foreach (FieldInfo f in m_Fields)
if (f.Name.Substring(0, 2) == "m_")
m_FieldMap[f.Name.Substring(2)] = f;
}
示例8: Open
public static IDbConnection Open(string dbPath, bool create)
{
if (dbPath == null)
throw new ArgumentNullException("dbPath");
if (create) {
if (File.Exists(dbPath))
File.Delete(dbPath);
#if WIN32
SQLiteConnection.CreateFile(dbPath);
#else
SqliteConnection.CreateFile(dbPath);
#endif
} else {
if (!File.Exists(dbPath))
throw new FileNotFoundException(string.Format("Database '{0}' not found", dbPath));
}
IDbConnection conn;
string connStr = string.Format("Data Source={0}", dbPath);
#if WIN32
conn = new SQLiteConnection(connStr);
#else
conn = new SqliteConnection(connStr);
#endif
conn.Open();
return conn;
}
示例9: IsValidCustomerLogin
public bool IsValidCustomerLogin(string email, string password)
{
//encode password
string encoded_password = Encoder.Encode(password);
//check email/password
string sql = "select * from CustomerLogin where email = '" + email + "' and password = '" +
encoded_password + "';";
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
connection.Open();
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
//TODO: User reader instead (for all calls)
DataSet ds = new DataSet();
da.Fill(ds);
try
{
return ds.Tables[0].Rows.Count == 0;
}
catch (Exception ex)
{
//Log this and pass the ball along.
log.Error("Error checking login", ex);
throw new Exception("Error checking login", ex);
}
}
}
示例10: DrinkDatabase
public DrinkDatabase(string dbPath)
{
path = dbPath;
// create the tables
bool exists = File.Exists(dbPath);
if (!exists)
{
connection = new SqliteConnection("Data Source=" + dbPath);
connection.Open();
var commands = new[] {
"CREATE TABLE [Items] (_id INTEGER PRIMARY KEY ASC, Name NTEXT, About NTEXT, Volume REAL, AlcoholByVolume REAL, IconNumber INTEGER);"
};
foreach (var command in commands)
{
using (var c = connection.CreateCommand())
{
c.CommandText = command;
c.ExecuteNonQuery();
}
}
initializeValues();
}
}
示例11: ClickGameStart
public void ClickGameStart()
{
del_InsertNewUserInfo InsertInfo = () =>
{
string conn = "URI=file:" + Application.dataPath +
"/StreamingAssets/GameUserDB/userDB.db";
using (IDbConnection dbconn = new SqliteConnection(conn))
{
dbconn.Open(); //Open connection to the database.
using (IDbCommand dbcmd = dbconn.CreateCommand())
{
try
{
string sqlQuery =
"INSERT INTO USER_INFO(name, level, type) " +
"VALUES(" + "'" + chName.text + "'" + ", " +
"'" + chLevel.text + "'" + ", " +
"'" + chType.text + "'" + ")";
dbcmd.CommandText = sqlQuery;
dbcmd.ExecuteNonQuery();
}
catch(SqliteException e)
{
// 이미 등록된 캐릭터이다.
Debug.Log(e.Message);
}
}
dbconn.Close();
}
};
InsertInfo();
GameLoadingProcess();
}
示例12: 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;
}
示例13: PreKeyring
static PreKeyring()
{
try
{
log.Debug("Opening SQL connection...");
PreKeyring.conn = new SqliteConnection();
SqliteConnectionStringBuilder connStr = new SqliteConnectionStringBuilder();
connStr.DataSource = Config.PrekeyringFile_Path;
//connStr.Password = Config.PrekeyringFile_Password;
PreKeyring.conn.ConnectionString = connStr.ToString();
connectString = connStr.ToString();
if ( Directory.Exists( Config.PrekeyringFile_Dir ) == false )
Directory.CreateDirectory( Config.PrekeyringFile_Dir );
if ( File.Exists( Config.PrekeyringFile_Path ) == false )
{
SqliteConnection.CreateFile( Config.PrekeyringFile_Path );
CreateTablesByStructures( PreKeyring.TableName );
}
conn.Open();
}
catch ( SqliteException ex )
{
SecuruStikException sex = new SecuruStikException( SecuruStikExceptionType.Init_Database,"SQLite - Create/Connect Failed." , ex );
throw sex;
}
finally
{
PreKeyring.conn.Close();
}
}
示例14: GetAllFeeds
/// <summary>
/// Returns all subscribed feeds.
/// </summary>
public IEnumerable<Feed> GetAllFeeds()
{
var feeds = new List<Feed>();
using (var connection = new SqliteConnection("Data Source=" + dbPath))
using (var query = new SqliteCommand("SELECT * FROM Feeds", connection))
{
connection.Open();
var reader = query.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
var feed = new Feed();
feed.Id = int.Parse(reader["id"].ToString());
feed.Name = reader ["name"].ToString();
feed.Url = reader ["url"].ToString();
feed.LastUpdated = DateTime.Parse (reader ["LastUpdated"].ToString ());
feed.CategoryId = int.Parse(reader["categoryId"].ToString());
feeds.Add(feed);
}
reader.Close();
}
return feeds;
}
示例15: LoadFavoriteBill
public Bill LoadFavoriteBill(int id)
{
Bill favBill;
using (var connection = new SqliteConnection (connectionString)) {
using (var cmd = connection.CreateCommand ()) {
connection.Open ();
cmd.CommandText = "SELECT * FROM FavoriteBills WHERE id = @id";
var idParam = new SqliteParameter ("@id", id);
cmd.Parameters.Add (idParam);
using (var reader = cmd.ExecuteReader ()) {
reader.Read ();
favBill = new Bill {
Id = Convert.ToInt32 (reader ["id"]),
Title = (string)reader ["title"],
ThomasLink = (string)reader ["thomas_link"],
Notes = reader["notes"] == DBNull.Value ? "" : (string)reader["notes"]
};
}
}
}
return favBill;
}