本文整理汇总了C#中Mono.Data.Sqlite.SqliteConnection.CreateCommand方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.CreateCommand方法的具体用法?C# SqliteConnection.CreateCommand怎么用?C# SqliteConnection.CreateCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.SqliteConnection
的用法示例。
在下文中一共展示了SqliteConnection.CreateCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: 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;
}
}
示例3: 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;
}
示例4: 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;
}
示例5: getDatabase
public static User getDatabase()
{
User result = new User();
using (SqliteConnection co = new SqliteConnection("Data Source=" + databasePath))
{
co.Open();
SqliteCommand cmd = co.CreateCommand();
cmd.CommandText = "Select * From User";
try
{
SqliteDataReader read = cmd.ExecuteReader();
if(read.Read())
{
try { result.usrID = (string)read["ID"]; } catch { result.usrID = ""; }
try { result.phrase = (string)read["Name"]; } catch { throw new Exception("NO Passphrase"); }
try { result.usrCH = (string)read["Chor"]; } catch { result.usrCH = ""; }
try { result.storage = (List<Appointment>)read["Appointments"]; } catch { }
}
}
catch(Exception ex)
{
Console.Write(ex);
}
}
return result;
}
示例6: HandleTouchUpInside
/// <summary>
/// This code will handle creating the database and a table.
/// </summary>
void HandleTouchUpInside(object sender, EventArgs e)
{
// Create the database
var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var pathToDatabase = Path.Combine(documents, "db_adonet.db");
SqliteConnection.CreateFile(pathToDatabase);
var msg = "Created new database at " + pathToDatabase;
// Create a table
var connectionString = String.Format("Data Source={0};Version=3;", pathToDatabase);
using (var conn= new SqliteConnection(connectionString))
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "CREATE TABLE People (PersonID INTEGE" +
"R PRIMARY KEY AUTOINCREMENT , FirstName ntext, LastName ntext)";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
// Let the user know that the database was created, and disable the button
// to prevent double clicks.
_txtView.Text = msg;
_btnCreateDatabase.Enabled = false;
}
示例7: 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;
}
示例8: 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;
}
示例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: 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;
}
示例11: Start
// Use this for initialization
void Start()
{
string conn = "URI=file:" + Application.dataPath + "/sqlite_userinfo";
IDbConnection dbconn = new SqliteConnection(conn);
dbconn.Open();
IDbCommand dbcmd = dbconn.CreateCommand();
string query = "SELECT idx, name, email FROM userinfo";
dbcmd.CommandText = query;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read())
{
int idx = reader.GetInt32(0);
string name = reader.GetString(1);
string email = reader.GetString(2);
Debug.Log("idx : " + idx + ", name : " + name + ", email : " + email);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
示例12: SqliteTransaction
/// <summary>
/// Constructs the transaction object, binding it to the supplied connection
/// </summary>
/// <param name="connection">The connection to open a transaction on</param>
/// <param name="deferredLock">TRUE to defer the writelock, or FALSE to lock immediately</param>
internal SqliteTransaction(SqliteConnection connection, bool deferredLock)
{
_cnn = connection;
_version = _cnn._version;
_level = (deferredLock == true) ? IsolationLevel.ReadCommitted : IsolationLevel.Serializable;
if (_cnn._transactionLevel++ == 0)
{
try
{
using (SqliteCommand cmd = _cnn.CreateCommand())
{
if (!deferredLock)
cmd.CommandText = "BEGIN IMMEDIATE";
else
cmd.CommandText = "BEGIN";
cmd.ExecuteNonQuery();
}
}
catch (SqliteException)
{
_cnn._transactionLevel--;
_cnn = null;
throw;
}
}
}
示例13: CodeProjectDatabase
public CodeProjectDatabase ()
{
dbPath = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.Personal),
"items.db3");
bool exists = File.Exists (dbPath);
if (!exists) {
SqliteConnection.CreateFile (dbPath);
}
var connection = new SqliteConnection ("Data Source=" + dbPath);
connection.Open ();
if (!exists) {
var commands = new[]{
"CREATE TABLE [Member] (Key integer, Name ntext, ArticleCnt integer, BlogCnt integer, Reputation ntext, IsMe integer);"
};
foreach (var command in commands) {
using (var c = connection.CreateCommand ()) {
c.CommandText = command;
c.ExecuteNonQuery ();
}
}
}
}
示例14: 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();
}
示例15: 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);
}