本文整理汇总了C#中Mono.Data.SqliteClient.SqliteCommand.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteCommand.ExecuteNonQuery方法的具体用法?C# SqliteCommand.ExecuteNonQuery怎么用?C# SqliteCommand.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.SqliteClient.SqliteCommand
的用法示例。
在下文中一共展示了SqliteCommand.ExecuteNonQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteNonQuery
//////////////////////////////////////////////////////////////
//
// All non queries are funneled through one connection
// to increase performance a little
//
protected int ExecuteNonQuery(SqliteCommand cmd)
{
lock (m_Connection)
{
cmd.Connection = m_Connection;
return cmd.ExecuteNonQuery();
}
}
示例2: WrongSyntax
public void WrongSyntax()
{
SqliteCommand insertCmd = new SqliteCommand("INSERT INTO t1 VALUES (,')",_conn);
using(_conn)
{
_conn.Open();
int res = insertCmd.ExecuteNonQuery();
Assert.AreEqual(res,1);
}
}
示例3: InsertRandomValuesWithParameter
public void InsertRandomValuesWithParameter()
{
SqliteParameter textP = new SqliteParameter();
textP.ParameterName = "textP";
textP.SourceColumn = "t";
SqliteParameter floatP = new SqliteParameter();
floatP.ParameterName = "floatP";
floatP.SourceColumn = "nu";
SqliteParameter integerP = new SqliteParameter();
integerP.ParameterName ="integerP";
integerP.SourceColumn = "i";
SqliteParameter blobP = new SqliteParameter();
blobP.ParameterName = "blobP";
blobP.SourceColumn = "b";
Random random = new Random();
StringBuilder builder = new StringBuilder();
for (int k=0; k < random.Next(0,100); k++)
{
builder.Append((char)random.Next(65536));
}
SqliteCommand insertCmd = new SqliteCommand("DELETE FROM t1; INSERT INTO t1 (t, f, i, b ) VALUES(:textP,:floatP,:integerP,:blobP)",_conn);
insertCmd.Parameters.Add(textP);
insertCmd.Parameters.Add(floatP);
insertCmd.Parameters.Add(blobP);
insertCmd.Parameters.Add(integerP);
textP.Value=builder.ToString();
floatP.Value=Convert.ToInt64(random.Next(999));
integerP.Value=random.Next(999);
blobP.Value=System.Text.Encoding.UTF8.GetBytes("\u05D0\u05D1\u05D2" + builder.ToString());
SqliteCommand selectCmd = new SqliteCommand("SELECT * from t1", _conn);
using(_conn)
{
_conn.Open();
int res = insertCmd.ExecuteNonQuery();
Assert.AreEqual(res,1);
using (IDataReader reader = selectCmd.ExecuteReader()) {
Assert.AreEqual(reader.Read(), true);
Assert.AreEqual(reader["t"], textP.Value);
Assert.AreEqual(reader["f"], floatP.Value);
Assert.AreEqual(reader["i"], integerP.Value);
Assert.AreEqual(reader["b"], blobP.Value);
Assert.AreEqual(reader.Read(), false);
}
}
}
示例4: ExecuteNonQuery
public new void ExecuteNonQuery(string sql, string connectionString)
{
using (SqliteConnection conn = new SqliteConnection(connectionString))
{
SqliteCommand cmd = new SqliteCommand(sql, conn);
cmd.CommandTimeout = 1200;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
示例5: ExecuteNonQuery
//////////////////////////////////////////////////////////////
//
// All non queries are funneled through one connection
// to increase performance a little
//
protected int ExecuteNonQuery(SqliteCommand cmd, SqliteConnection connection)
{
lock (connection)
{
SqliteConnection newConnection =
(SqliteConnection)((ICloneable)connection).Clone();
newConnection.Open();
cmd.Connection = newConnection;
//Console.WriteLine("XXX " + cmd.CommandText);
return cmd.ExecuteNonQuery();
}
}
示例6: Database
public Database(string file)
{
bool create = false;
if (!File.Exists (file)) {
create = true;
}
try {
StreamReader srVersion = new StreamReader (file+".version");
dbVersion = srVersion.ReadToEnd ();
if (dbVersion != null) {
dbVersion = dbVersion.Trim();
}
srVersion.Close();
}
catch {
dbVersion = null;
}
string connectionString = "URI=file:"+file;
connection = new SqliteConnection(connectionString);
connection.Open();
command = connection.CreateCommand();
if (create) {
Conf.EmptyCache();
Assembly thisAssembly = Assembly.GetEntryAssembly ();
Stream stream = thisAssembly.GetManifestResourceStream("Database.sql");
if (stream != null) {
StreamReader sr = new StreamReader (stream);
string sql = sr.ReadToEnd();
command.CommandText = sql;
command.ExecuteNonQuery();
StreamWriter swVersion = new StreamWriter (file+".version", false);
swVersion.Write (Defines.VERSION);
swVersion.Close();
dbVersion = Defines.VERSION;
}
else {
System.Console.WriteLine("Error creating the database");
}
}
if (dbVersion == null || !dbVersion.Equals (Defines.VERSION)) {
UpdateDatabase(file, dbVersion);
}
}
示例7: Convert
public bool Convert()
{
try
{
SqliteConnection conn = new SqliteConnection(m_connectionString);
conn.Open();
Assembly assem = GetType().Assembly;
Migration m = new Migration(conn, assem, "InventoryStore");
if (m.Version == 0)
{
//Apply all changes to db
SqliteCommand addSalePriceCmd = new SqliteCommand(addSalePrice, conn);
addSalePriceCmd.ExecuteNonQuery();
SqliteCommand addSaleTypeCmd = new SqliteCommand(addSaleType, conn);
addSaleTypeCmd.ExecuteNonQuery();
SqliteCommand addCreationDateCmd = new SqliteCommand(addCreationDate, conn);
addCreationDateCmd.ExecuteNonQuery();
SqliteCommand addGroupIDCmd = new SqliteCommand(addGroupID, conn);
addGroupIDCmd.ExecuteNonQuery();
SqliteCommand addGroupOwnedCmd = new SqliteCommand(addGroupOwned, conn);
addGroupOwnedCmd.ExecuteNonQuery();
SqliteCommand addFlagsCmd = new SqliteCommand(addFlags, conn);
addFlagsCmd.ExecuteNonQuery();
//then change version number
m.Version = 1;
}
return true;
}
catch (Exception e)
{
m_log.ErrorFormat("[InventoryStore] Migration failed. Reason: {0}", e);
return false;
}
}
示例8: Create
public void Create()
{
try
{
if(File.Exists(_uri))
{
_conn.Dispose();
// We want to start with a fresh db for each full run
// The database is created on the first open()
File.Delete(_uri);
_conn = new SqliteConnection (_connectionString);
}
}
catch(Exception e)
{
throw e;
}
SqliteCommand createCommand = new SqliteCommand("CREATE TABLE t1(t TEXT, f FLOAT, i INTEGER, b TEXT);",_conn);
SqliteCommand insertCommand = new SqliteCommand("INSERT INTO t1 (t, f, i, b ) VALUES('" + stringvalue + "',123,123,'123')",_conn);
try
{
_conn.Open();
createCommand.ExecuteNonQuery();
insertCommand.ExecuteNonQuery();
}
catch(Exception e)
{
throw new AssertionException("Create table failed",e);
}
finally
{
_conn.Close();
}
}
示例9: NewEntry
/// <summary>
/// Creates a new entry in the cache file.
/// </summary>
/// <param name="entry">The entry to create.</param>
/// <returns>The new entry's contentId.</returns>
public uint NewEntry(ContentEntry entry)
{
uint active = 1;
if (!entry.Active)
{
active = 0;
}
uint activate = (uint)((TimeSpan)entry.Activate.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0))).TotalSeconds;
uint expiry = 0;
if (entry.Expires)
{
expiry = (uint)((TimeSpan)entry.Expiry.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0))).TotalSeconds;
}
String p = entry.GetPropsAsString();
SqliteCommand query = new SqliteCommand(@"INSERT INTO [content] ([active], [activate], [expire], [dayparts], [contentType], [descriptor], [size], [viewcount], [viewlimit], [displayafter], [props], [data]) VALUES (@active, @activate, @expire, @dayparts, @contentType, @descriptor, @size, @viewcount, @viewlimit, @displayafter, @props, @data); SELECT last_insert_rowid() AS contentId;", sqlite);
query.Parameters.Add(new SqliteParameter("@active", (int)active));
query.Parameters.Add(new SqliteParameter("@activate", (int)activate));
query.Parameters.Add(new SqliteParameter("@expire", (int)expiry));
query.Parameters.Add(new SqliteParameter("@dayparts", (int)entry.DayParts));
query.Parameters.Add(new SqliteParameter("@contentType", (int)entry.contentType.contentType));
query.Parameters.Add(new SqliteParameter("@descriptor", entry.Descriptor));
query.Parameters.Add(new SqliteParameter("@size", (int)entry.Size));
query.Parameters.Add(new SqliteParameter("@viewcount", (int)entry.ViewCount));
query.Parameters.Add(new SqliteParameter("@viewlimit", (int)entry.ViewLimit));
query.Parameters.Add(new SqliteParameter("@displayafter", (int)entry.DisplayAfter));
query.Parameters.Add(new SqliteParameter("@props", p));
query.Parameters.Add(new SqliteParameter("@data", entry.Data));
// get the contentId back
sqlite.Open();
Object cidR = query.ExecuteScalar();
uint cid = (uint)((long)cidR);
// shove cid into props
p = "contentId=" + cid.ToString() + "&" + p;
// reset connection
sqlite.Close();
sqlite.Open();
// shove in updated props
query = new SqliteCommand(@"UPDATE [content] SET [props][email protected] WHERE [contentId][email protected]", sqlite);
query.Parameters.Add(new SqliteParameter("@props", p));
query.Parameters.Add(new SqliteParameter("@cid", (int)cid));
if (query.ExecuteNonQuery() == 0)
{
sqlite.Close();
throw new DatabaseUpdateFailureException();
}
// reset connection
sqlite.Close();
sqlite.Open();
// shove in corresponding contentlist entry for record
query = new SqliteCommand(@"INSERT INTO [contentlist] ([appId], [contentType], [contentId], [userInfo], [zoneId]) VALUES (@appid, @contentType, @cid, @userinfo, @zoneid)", sqlite);
query.Parameters.Add(new SqliteParameter("@appid", this._appID));
query.Parameters.Add(new SqliteParameter("@contentType", (int)entry.contentType.contentType));
query.Parameters.Add(new SqliteParameter("@cid", (int)cid));
query.Parameters.Add(new SqliteParameter("@zoneid", entry.Properties["zoneId"]));
query.Parameters.Add(new SqliteParameter("@userinfo", entry.Properties["userInfo"]));
if (query.ExecuteNonQuery() == 0)
{
sqlite.Close();
throw new DatabaseUpdateFailureException();
}
sqlite.Close();
return cid;
}
示例10: ImportImage
/// <summary>
/// Imports a single image into the database.
/// </summary>
/// <param name="contentId">The position to place the image.</param>
/// <param name="ddsimage">The image data.</param>
public void ImportImage(uint contentId, byte[] ddsimage)
{
sqlite.Open();
SqliteCommand query = new SqliteCommand(@"UPDATE [content] SET [data] = @data, [size] = @size WHERE [contentId] = @cid", sqlite);
query.Parameters.Add(new SqliteParameter("@data", ddsimage));
query.Parameters.Add(new SqliteParameter("@size", ddsimage.Length));
query.Parameters.Add(new SqliteParameter("@cid", (int)contentId));
if (query.ExecuteNonQuery() == 0)
{
sqlite.Close();
throw new DatabaseUpdateFailureException();
}
sqlite.Close();
}
示例11: EditEntry
/// <summary>
/// Updates the entry an the specified contentId.
/// </summary>
/// <param name="contentID">The contentId to update.</param>
/// <param name="entry">The new content of the row.</param>
/// <param name="UpdateData">Should the image/video data column be updated?</param>
public void EditEntry(uint contentID, ContentEntry entry, bool UpdateData)
{
uint active = 1;
if (!entry.Active)
{
active = 0;
}
uint activate = (uint)((TimeSpan)entry.Activate.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0))).TotalSeconds;
uint expiry = 0;
if (entry.Expires)
{
expiry = (uint)((TimeSpan)entry.Expiry.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, 0))).TotalSeconds;
}
String propS = entry.GetPropsAsString();
sqlite.Open();
SqliteCommand query = new SqliteCommand(@"UPDATE [content] SET [active][email protected], [activate][email protected], [expire][email protected], [dayparts][email protected], [contentType][email protected], [descriptor][email protected], [size][email protected], [viewcount][email protected], [viewlimit][email protected], [displayafter][email protected], [props][email protected] WHERE [contentId][email protected]", sqlite);
//query = new SqliteCommand(@"UPDATE [content] SET [active][email protected], [activate][email protected], [expire][email protected], [props][email protected] WHERE [contentId][email protected]", sqlite);
query.Parameters.Add(new SqliteParameter("@cid", (int)contentID));
query.Parameters.Add(new SqliteParameter("@active", (int)active));
query.Parameters.Add(new SqliteParameter("@activate", (int)activate));
query.Parameters.Add(new SqliteParameter("@expire", (int)expiry));
query.Parameters.Add(new SqliteParameter("@dayparts", (int)entry.DayParts));
query.Parameters.Add(new SqliteParameter("@contentType", (int)entry.contentType.contentType));
query.Parameters.Add(new SqliteParameter("@descriptor", entry.Descriptor));
query.Parameters.Add(new SqliteParameter("@size", (int)entry.Size));
query.Parameters.Add(new SqliteParameter("@viewcount", (int)entry.ViewCount));
query.Parameters.Add(new SqliteParameter("@viewlimit", (int)entry.ViewLimit));
query.Parameters.Add(new SqliteParameter("@displayafter", (int)entry.DisplayAfter));
query.Parameters.Add(new SqliteParameter("@props", propS));
if (query.ExecuteNonQuery() != 1)
{
sqlite.Close();
throw new DatabaseUpdateFailureException();
}
sqlite.Close();
sqlite.Open();
// update contentlist
query = new SqliteCommand(@"UPDATE [contentlist] SET [zoneId][email protected], [contentType][email protected], [userInfo][email protected] WHERE [contentId][email protected]", sqlite);
query.Parameters.Add(new SqliteParameter("@cid", (int)contentID));
query.Parameters.Add(new SqliteParameter("@contentType", (int)entry.contentType.contentType));
query.Parameters.Add(new SqliteParameter("@zoneid", entry.Properties["zoneId"]));
query.Parameters.Add(new SqliteParameter("@userinfo", entry.Properties["userInfo"]));
if (query.ExecuteNonQuery() == 0)
{
sqlite.Close();
throw new DatabaseUpdateFailureException();
}
sqlite.Close();
if (UpdateData)
{
this.ImportImage(contentID, entry.Data);
}
}
示例12: DeleteEntry
/// <summary>
/// Deletes a record from the database.
/// </summary>
/// <param name="contentId">The record's contentId to delete.</param>
public void DeleteEntry(uint contentId)
{
sqlite.Open();
SqliteCommand query = new SqliteCommand(@"DELETE FROM [content] WHERE [contentId][email protected]", sqlite);
query.Parameters.Add(new SqliteParameter("@cid", (int)contentId));
if (query.ExecuteNonQuery() != 1)
{
sqlite.Close();
throw new DatabaseUpdateFailureException();
}
sqlite.Close();
sqlite.Open();
query = new SqliteCommand(@"DELETE FROM [contentlist] WHERE [contentId][email protected]", sqlite);
query.Parameters.Add(new SqliteParameter("@cid", (int)contentId));
// don't error check here as old versions of the software never touched
// this table, so it may be inconsistant.
query.ExecuteNonQuery();
sqlite.Close();
}
示例13: UpdateUserStats
public void UpdateUserStats(UserSessionID uid, SqliteConnection db)
{
if (uid.session_id == UUID.Zero)
return;
lock (db)
{
SqliteCommand updatecmd = new SqliteCommand(SQL_STATS_TABLE_UPDATE, db);
updatecmd.Parameters.Add(new SqliteParameter(":session_id", uid.session_data.session_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":agent_id", uid.session_data.agent_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":region_id", uid.session_data.region_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":last_updated", (int) uid.session_data.last_updated));
updatecmd.Parameters.Add(new SqliteParameter(":remote_ip", uid.session_data.remote_ip));
updatecmd.Parameters.Add(new SqliteParameter(":name_f", uid.session_data.name_f));
updatecmd.Parameters.Add(new SqliteParameter(":name_l", uid.session_data.name_l));
updatecmd.Parameters.Add(new SqliteParameter(":avg_agents_in_view", uid.session_data.avg_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":min_agents_in_view",
(int) uid.session_data.min_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":max_agents_in_view",
(int) uid.session_data.max_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":mode_agents_in_view",
(int) uid.session_data.mode_agents_in_view));
updatecmd.Parameters.Add(new SqliteParameter(":avg_fps", uid.session_data.avg_fps));
updatecmd.Parameters.Add(new SqliteParameter(":min_fps", uid.session_data.min_fps));
updatecmd.Parameters.Add(new SqliteParameter(":max_fps", uid.session_data.max_fps));
updatecmd.Parameters.Add(new SqliteParameter(":mode_fps", uid.session_data.mode_fps));
updatecmd.Parameters.Add(new SqliteParameter(":a_language", uid.session_data.a_language));
updatecmd.Parameters.Add(new SqliteParameter(":mem_use", uid.session_data.mem_use));
updatecmd.Parameters.Add(new SqliteParameter(":meters_traveled", uid.session_data.meters_traveled));
updatecmd.Parameters.Add(new SqliteParameter(":avg_ping", uid.session_data.avg_ping));
updatecmd.Parameters.Add(new SqliteParameter(":min_ping", uid.session_data.min_ping));
updatecmd.Parameters.Add(new SqliteParameter(":max_ping", uid.session_data.max_ping));
updatecmd.Parameters.Add(new SqliteParameter(":mode_ping", uid.session_data.mode_ping));
updatecmd.Parameters.Add(new SqliteParameter(":regions_visited", uid.session_data.regions_visited));
updatecmd.Parameters.Add(new SqliteParameter(":run_time", uid.session_data.run_time));
updatecmd.Parameters.Add(new SqliteParameter(":avg_sim_fps", uid.session_data.avg_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":min_sim_fps", uid.session_data.min_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":max_sim_fps", uid.session_data.max_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":mode_sim_fps", uid.session_data.mode_sim_fps));
updatecmd.Parameters.Add(new SqliteParameter(":start_time", uid.session_data.start_time));
updatecmd.Parameters.Add(new SqliteParameter(":client_version", uid.session_data.client_version));
updatecmd.Parameters.Add(new SqliteParameter(":s_cpu", uid.session_data.s_cpu));
updatecmd.Parameters.Add(new SqliteParameter(":s_gpu", uid.session_data.s_gpu));
updatecmd.Parameters.Add(new SqliteParameter(":s_os", uid.session_data.s_os));
updatecmd.Parameters.Add(new SqliteParameter(":s_ram", uid.session_data.s_ram));
updatecmd.Parameters.Add(new SqliteParameter(":d_object_kb", uid.session_data.d_object_kb));
updatecmd.Parameters.Add(new SqliteParameter(":d_texture_kb", uid.session_data.d_texture_kb));
updatecmd.Parameters.Add(new SqliteParameter(":d_world_kb", uid.session_data.d_world_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_in_kb", uid.session_data.n_in_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_in_pk", uid.session_data.n_in_pk));
updatecmd.Parameters.Add(new SqliteParameter(":n_out_kb", uid.session_data.n_out_kb));
updatecmd.Parameters.Add(new SqliteParameter(":n_out_pk", uid.session_data.n_out_pk));
updatecmd.Parameters.Add(new SqliteParameter(":f_dropped", uid.session_data.f_dropped));
updatecmd.Parameters.Add(new SqliteParameter(":f_failed_resends", uid.session_data.f_failed_resends));
updatecmd.Parameters.Add(new SqliteParameter(":f_invalid", uid.session_data.f_invalid));
updatecmd.Parameters.Add(new SqliteParameter(":f_off_circuit", uid.session_data.f_off_circuit));
updatecmd.Parameters.Add(new SqliteParameter(":f_resent", uid.session_data.f_resent));
updatecmd.Parameters.Add(new SqliteParameter(":f_send_packet", uid.session_data.f_send_packet));
updatecmd.Parameters.Add(new SqliteParameter(":session_key", uid.session_data.session_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":agent_key", uid.session_data.agent_id.ToString()));
updatecmd.Parameters.Add(new SqliteParameter(":region_key", uid.session_data.region_id.ToString()));
m_log.Debug("UPDATE");
int result = updatecmd.ExecuteNonQuery();
if (result == 0)
{
m_log.Debug("INSERT");
updatecmd.CommandText = SQL_STATS_TABLE_INSERT;
try
{
updatecmd.ExecuteNonQuery();
}
catch
(SqliteExecutionException)
{
m_log.Warn("[WEBSTATS]: failed to write stats to storage Execution Exception");
}
catch (SqliteSyntaxException)
{
m_log.Warn("[WEBSTATS]: failed to write stats to storage SQL Syntax Exception");
}
}
}
}
示例14: CreateTables
private void CreateTables(SqliteConnection db)
{
using (SqliteCommand createcmd = new SqliteCommand(SQL_STATS_TABLE_CREATE, db))
{
createcmd.ExecuteNonQuery();
}
}
示例15: Test
static void Test(bool v3, string encoding) {
if (!v3)
Console.WriteLine("Testing Version 2" + (encoding != null ? " with " + encoding + " encoding" : ""));
else
Console.WriteLine("Testing Version 3");
System.IO.File.Delete("SqliteTest.db");
SqliteConnection dbcon = new SqliteConnection();
// the connection string is a URL that points
// to a file. If the file does not exist, a
// file is created.
// "URI=file:some/path"
string connectionString =
"URI=file:SqliteTest.db";
if (v3)
connectionString += ",Version=3";
if (encoding != null)
connectionString += ",encoding=" + encoding;
dbcon.ConnectionString = connectionString;
dbcon.Open();
SqliteCommand dbcmd = new SqliteCommand();
dbcmd.Connection = dbcon;
dbcmd.CommandText =
"CREATE TABLE MONO_TEST ( " +
"NID INT, " +
"NDESC TEXT, " +
"NTIME DATETIME); " +
"INSERT INTO MONO_TEST " +
"(NID, NDESC, NTIME) " +
"VALUES(1,'One (unicode test: \u05D0)', '2006-01-01')";
Console.WriteLine("Create & insert modified rows = 1: " + dbcmd.ExecuteNonQuery());
dbcmd.CommandText =
"INSERT INTO MONO_TEST " +
"(NID, NDESC, NTIME) " +
"VALUES(:NID,:NDESC,:NTIME)";
dbcmd.Parameters.Add( new SqliteParameter("NID", 2) );
dbcmd.Parameters.Add( new SqliteParameter(":NDESC", "Two (unicode test: \u05D1)") );
dbcmd.Parameters.Add( new SqliteParameter(":NTIME", DateTime.Now) );
Console.WriteLine("Insert modified rows with parameters = 1, 2: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());
dbcmd.CommandText =
"INSERT INTO MONO_TEST " +
"(NID, NDESC, NTIME) " +
"VALUES(3,'Three, quoted parameter test, and next is null; :NTIME', NULL)";
Console.WriteLine("Insert with null modified rows and ID = 1, 3: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());
dbcmd.CommandText =
"INSERT INTO MONO_TEST " +
"(NID, NDESC, NTIME) " +
"VALUES(4,'Four with ANSI char: ü', NULL)";
Console.WriteLine("Insert with ANSI char ü = 1, 4: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());
dbcmd.CommandText =
"INSERT INTO MONO_TEST " +
"(NID, NDESC, NTIME) " +
"VALUES(?,?,?)";
dbcmd.Parameters.Clear();
IDbDataParameter param1 = dbcmd.CreateParameter();
param1.DbType = DbType.DateTime;
param1.Value = 5;
dbcmd.Parameters.Add(param1);
IDbDataParameter param2 = dbcmd.CreateParameter();
param2.Value = "Using unnamed parameters";
dbcmd.Parameters.Add(param2);
IDbDataParameter param3 = dbcmd.CreateParameter();
param3.DbType = DbType.DateTime;
param3.Value = DateTime.Parse("2006-05-11 11:45:00");
dbcmd.Parameters.Add(param3);
Console.WriteLine("Insert with unnamed parameters = 1, 5: " + dbcmd.ExecuteNonQuery() + " , " + dbcmd.LastInsertRowID());
dbcmd.CommandText =
"SELECT * FROM MONO_TEST";
SqliteDataReader reader;
reader = dbcmd.ExecuteReader();
Console.WriteLine("read and display data...");
while(reader.Read())
for (int i = 0; i < reader.FieldCount; i++)
Console.WriteLine(" Col {0}: {1} (type: {2}, data type: {3})",
i, reader[i] == null ? "(null)" : reader[i].ToString(), reader[i] == null ? "(null)" : reader[i].GetType().FullName, reader.GetDataTypeName(i));
dbcmd.CommandText = "SELECT NDESC FROM MONO_TEST WHERE NID=2";
Console.WriteLine("read and display a scalar = 'Two': " + dbcmd.ExecuteScalar());
dbcmd.CommandText = "SELECT count(*) FROM MONO_TEST";
Console.WriteLine("read and display a non-column scalar = 3: " + dbcmd.ExecuteScalar());
Console.WriteLine("read and display data using DataAdapter/DataSet...");
SqliteDataAdapter adapter = new SqliteDataAdapter("SELECT * FROM MONO_TEST", connectionString);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
foreach(DataTable myTable in dataset.Tables){
foreach(DataRow myRow in myTable.Rows){
//.........这里部分代码省略.........