本文整理汇总了C#中NuoDb.Data.Client.NuoDbConnection类的典型用法代码示例。如果您正苦于以下问题:C# NuoDbConnection类的具体用法?C# NuoDbConnection怎么用?C# NuoDbConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NuoDbConnection类属于NuoDb.Data.Client命名空间,在下文中一共展示了NuoDbConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGameTable
internal static void CreateGameTable()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
connection.Open();
try
{
DbCommand dropCommand = new NuoDbCommand("drop table Game", connection);
dropCommand.ExecuteNonQuery();
}
catch (Exception)
{
// table is allowed to be missing
}
DbCommand createCommand = new NuoDbCommand("create table Game" +
"(" +
" Id bigint generated always as identity not NULL primary key," +
" Date DATE" +
")", connection);
createCommand.ExecuteNonQuery();
DbCommand insertCommand = new NuoDbCommand("Insert into Game (Date) Values (?)", connection);
insertCommand.Prepare();
insertCommand.Parameters[0].Value = "1970-01-01";
insertCommand.ExecuteNonQuery();
}
}
示例2: NuoDbCommand
public NuoDbCommand(string query, DbConnection conn)
{
if (!(conn is NuoDbConnection))
throw new ArgumentException("Connection is not a NuoDB connection", "conn");
sqlText = query;
connection = (NuoDbConnection)conn;
}
示例3: TestNoPrepareNamedParamIn
public void TestNoPrepareNamedParamIn()
{
using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
{
connection.Open();
new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
new NuoDbCommand("create procedure nunit_test(in p1 string, in p2 string) as throw p1; end_procedure", connection).ExecuteNonQuery();
NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
cmd.CommandType = CommandType.StoredProcedure;
NuoDbParameter param1 = new NuoDbParameter();
param1.ParameterName = "p2";
param1.Direction = ParameterDirection.Input;
param1.Value = "goodbye";
cmd.Parameters.Add(param1);
NuoDbParameter param2 = new NuoDbParameter();
param2.ParameterName = "p1";
param2.Direction = ParameterDirection.Input;
param2.Value = "hello";
cmd.Parameters.Add(param2);
try
{
cmd.ExecuteNonQuery();
Assert.Fail();
}
catch (Exception e)
{
Assert.AreEqual("hello", e.Message);
}
}
}
示例4: NuoDbDataReader
public NuoDbDataReader(NuoDbConnection connection, int handle, EncodedDataStream dataStream, NuoDbCommand statement, bool readColumnNames)
{
this.connection = connection;
this.handle = handle;
this.pendingRows = dataStream;
this.statement = statement;
if (this.handle != -1)
this.connection.InternalConnection.RegisterResultSet(this.handle);
this.numberColumns = this.pendingRows != null ? this.pendingRows.getInt() : 0;
this.values = new Value[numberColumns];
if (readColumnNames)
{
this.columnNames = new string[numberColumns];
for (int n = 0; n < numberColumns; ++n)
{
columnNames[n] = dataStream.getString();
}
}
else
{
//RemPreparedStatement ps = (RemPreparedStatement)statement;
//columnNames = ps.columnNames;
}
}
示例5: TestAsynchronousReader2
public void TestAsynchronousReader2()
{
NuoDbConnection connection = new NuoDbConnection(connectionString);
NuoDbCommand command = new NuoDbCommand("select * from hockey", connection);
connection.Open();
AsyncCallback callback = new AsyncCallback(HandleCallback);
IAsyncResult result = command.BeginExecuteReader(callback, command);
}
示例6: Init
public static void Init()
{
Utils.CreateHockeyTable();
using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
{
DbCommand command = new NuoDbCommand("select count(*) from hockey", connection);
connection.Open();
tableRows = (int)command.ExecuteScalar();
}
}
示例7: HelloDB
/*
* Creates an instance of HelloDB connected to the database with
* the given name on the localhost. This example class uses the
* default testing name & password.
*/
public HelloDB(string dbName)
{
NuoDbConnectionStringBuilder builder = new NuoDbConnectionStringBuilder();
builder.Server = "localhost";
builder.Database = dbName;
builder.User = "dba";
builder.Password = "goalie";
builder.Schema = "hello";
this.connection = new NuoDbConnection(builder.ConnectionString);
this.connection.Open();
}
示例8: TestMultipleReturnResultSets
public void TestMultipleReturnResultSets()
{
using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
{
connection.Open();
new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
try
{
new NuoDbCommand("create procedure nunit_test() " +
" returns table t1(field1 string, field2 integer), t2(column1 string, column2 string, column3 integer) " +
" as " +
" insert into t1 values ('rset 1, row1', 0), ('rset 1, row2',1); " +
" insert into t2 values ('rset 2, row1', 'first', 100), ('rset 2, row2','second', 101); " +
" end_procedure", connection).ExecuteNonQuery();
}
catch (NuoDbSqlException e)
{
if (e.Code.Code == -1)
{
// the server doesn't support multiple result sets as return value for procedures
return;
}
else
throw;
}
NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
cmd.CommandType = CommandType.StoredProcedure;
using (DbDataReader reader = cmd.ExecuteReader())
{
Assert.IsTrue(reader.Read());
Assert.AreEqual("rset 1, row1", reader["field1"]);
Assert.AreEqual(0, reader["field2"]);
Assert.IsTrue(reader.Read());
Assert.AreEqual("rset 1, row2", reader["field1"]);
Assert.AreEqual(1, reader["field2"]);
Assert.IsFalse(reader.Read());
Assert.IsTrue(reader.NextResult());
Assert.IsTrue(reader.Read());
Assert.AreEqual("rset 2, row1", reader["column1"]);
Assert.AreEqual("first", reader["column2"]);
Assert.AreEqual(100, reader["column3"]);
Assert.IsTrue(reader.Read());
Assert.AreEqual("rset 2, row2", reader["column1"]);
Assert.AreEqual("second", reader["column2"]);
Assert.AreEqual(101, reader["column3"]);
Assert.IsFalse(reader.Read());
Assert.IsFalse(reader.NextResult());
}
}
}
示例9: TestBulkLoadPerformance
public void TestBulkLoadPerformance()
{
using (NuoDbConnection cnn = new NuoDbConnection(connectionString))
{
cnn.Open();
Utils.DropTable(cnn, "temp");
DbCommand createCommand = new NuoDbCommand("create table temp (col1 integer, col2 integer)", cnn);
int result = createCommand.ExecuteNonQuery();
DbCommand cmm = cnn.CreateCommand();
cmm.CommandText = "insert into temp(col1, col2) values(?, ?)";
cmm.Parameters.Add(new NuoDbParameter { DbType = DbType.Int32, ParameterName = "col1" });
cmm.Parameters.Add(new NuoDbParameter { DbType = DbType.Int32, ParameterName = "col2" });
cmm.Prepare();
const int ROW_NUMBER = 40000;
DateTime start = DateTime.Now;
for (var i = 1; i <= ROW_NUMBER; i++)
{
cmm.Parameters["col1"].Value = i;
cmm.Parameters["col2"].Value = 2 * i;
cmm.ExecuteNonQuery();
}
DateTime end = DateTime.Now;
double insertTime = (end - start).TotalMilliseconds;
Utils.DropTable(cnn, "temp2");
createCommand = new NuoDbCommand("create table temp2 (col1 integer, col2 integer)", cnn);
createCommand.ExecuteNonQuery();
NuoDbBulkLoader loader = new NuoDbBulkLoader(connectionString);
loader.DestinationTableName = "TEMP2";
DbCommand command = new NuoDbCommand("select * from temp", cnn);
DbDataReader reader = command.ExecuteReader();
loader.BatchProcessed += new BatchProcessedEventHandler(loader_BatchProcessed);
start = DateTime.Now;
loader.WriteToServer(reader);
end = DateTime.Now;
double loadTime = (end - start).TotalMilliseconds;
reader.Close();
Console.WriteLine("{0} insert = {1}\n{0} bulk load = {2}\n", ROW_NUMBER, insertTime, loadTime);
Assert.IsTrue(loadTime < insertTime, "BulkLoad takes more time than manual insertion");
}
}
示例10: TestNoPrepareAnonymousParamOut
public void TestNoPrepareAnonymousParamOut()
{
using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
{
connection.Open();
new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
new NuoDbCommand("create procedure nunit_test(out p1 string) as p1='hello'; end_procedure", connection).ExecuteNonQuery();
NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
Assert.AreEqual("hello", cmd.Parameters["p1"].Value);
}
}
示例11: TestAsynchronousScalar1
public void TestAsynchronousScalar1()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
NuoDbCommand countCommand = (NuoDbCommand)connection.CreateCommand();
countCommand.CommandText = "select count(*) from hockey";
connection.Open();
IAsyncResult result = countCommand.BeginExecuteScalar();
int count = (int)countCommand.EndExecuteScalar(result);
}
}
示例12: NuoDbDatabaseExists
protected bool NuoDbDatabaseExists(string connectionString)
{
try
{
//just try to connect
using (var conn = new NuoDbConnection(connectionString))
{
conn.Open();
}
return true;
}
catch
{
return false;
}
}
示例13: DB4329
public void DB4329()
{
using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
{
connection.Open();
Utils.DropTable(connection, "ExpenseTest");
DbCommand createCommand = new NuoDbCommand("Create table ExpenseTest" +
"(" +
"SourceExpenseId int," +
"ExpenseAmount numeric(15,2)" +
")", connection);
createCommand.ExecuteNonQuery();
DbCommand insertCommand = new NuoDbCommand("Insert Into ExpenseTest(SourceExpenseId, ExpenseAmount) Values (?,?)", connection);
insertCommand.Prepare();
insertCommand.Parameters[0].Value = -1254524;
insertCommand.Parameters[1].Value = -135.35;
insertCommand.ExecuteNonQuery();
insertCommand.Parameters[0].Value = 100100100;
insertCommand.Parameters[1].Value = -1325465.35;
insertCommand.ExecuteNonQuery();
insertCommand.Parameters[0].Value = 100100101;
insertCommand.Parameters[1].Value = 200000.35;
insertCommand.ExecuteNonQuery();
DbCommand selectCommand = new NuoDbCommand("select SourceExpenseId, ExpenseAmount from ExpenseTest", connection);
using (DbDataReader reader = selectCommand.ExecuteReader())
{
bool hasNext=reader.Read();
Assert.IsTrue(hasNext);
Assert.AreEqual(-1254524, reader[0]);
Assert.AreEqual(-135.35, reader[1]);
hasNext = reader.Read();
Assert.IsTrue(hasNext);
Assert.AreEqual(100100100, reader[0]);
Assert.AreEqual(-1325465.35, reader[1]);
hasNext = reader.Read();
Assert.IsTrue(hasNext);
Assert.AreEqual(100100101, reader[0]);
Assert.AreEqual(200000.35, reader[1]);
}
}
}
示例14: TestAsynchronousReader1
public void TestAsynchronousReader1()
{
using (NuoDbConnection connection = new NuoDbConnection(connectionString))
{
NuoDbCommand command = new NuoDbCommand("select * from hockey", connection);
connection.Open();
IAsyncResult result = command.BeginExecuteReader();
using (DbDataReader reader = command.EndExecuteReader(result))
{
while (reader.Read())
{
Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", reader[0], reader[1], reader[2], reader["id"]);
}
}
}
}
示例15: TestNoPrepareAnonymousParamIn
public void TestNoPrepareAnonymousParamIn()
{
using (NuoDbConnection connection = new NuoDbConnection(TestFixture1.connectionString))
{
connection.Open();
new NuoDbCommand("drop procedure nunit_test if exists", connection).ExecuteNonQuery();
new NuoDbCommand("create procedure nunit_test(in p1 string) as throw p1; end_procedure", connection).ExecuteNonQuery();
NuoDbCommand cmd = new NuoDbCommand("nunit_test", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("hello");
try
{
cmd.ExecuteNonQuery();
Assert.Fail();
}
catch (Exception e)
{
Assert.AreEqual("hello", e.Message);
}
}
}