本文整理汇总了C#中FirebirdSql.Data.FirebirdClient.FbCommand.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# FbCommand.Prepare方法的具体用法?C# FbCommand.Prepare怎么用?C# FbCommand.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FirebirdSql.Data.FirebirdClient.FbCommand
的用法示例。
在下文中一共展示了FbCommand.Prepare方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertTestData
private static void InsertTestData(string connectionString)
{
FbConnection connection = new FbConnection(connectionString);
connection.Open();
StringBuilder commandText = new StringBuilder();
commandText.Append("insert into test (int_field, char_field, varchar_field, bigint_field, smallint_field, float_field, double_field, numeric_field, date_field, time_field, timestamp_field, clob_field, blob_field)");
commandText.Append(" values(@int_field, @char_field, @varchar_field, @bigint_field, @smallint_field, @float_field, @double_field, @numeric_field, @date_field, @time_field, @timestamp_field, @clob_field, @blob_field)");
FbTransaction transaction = connection.BeginTransaction();
FbCommand command = new FbCommand(commandText.ToString(), connection, transaction);
try
{
// Add command parameters
command.Parameters.Add("@int_field", FbDbType.Integer);
command.Parameters.Add("@char_field", FbDbType.Char);
command.Parameters.Add("@varchar_field", FbDbType.VarChar);
command.Parameters.Add("@bigint_field", FbDbType.BigInt);
command.Parameters.Add("@smallint_field", FbDbType.SmallInt);
command.Parameters.Add("@float_field", FbDbType.Double);
command.Parameters.Add("@double_field", FbDbType.Double);
command.Parameters.Add("@numeric_field", FbDbType.Numeric);
command.Parameters.Add("@date_field", FbDbType.Date);
command.Parameters.Add("@time_Field", FbDbType.Time);
command.Parameters.Add("@timestamp_field", FbDbType.TimeStamp);
command.Parameters.Add("@clob_field", FbDbType.Text);
command.Parameters.Add("@blob_field", FbDbType.Binary);
command.Prepare();
for (int i = 0; i < 100; i++)
{
command.Parameters["@int_field"].Value = i;
command.Parameters["@char_field"].Value = "IRow " + i.ToString();
command.Parameters["@varchar_field"].Value = "IRow Number " + i.ToString();
command.Parameters["@bigint_field"].Value = i;
command.Parameters["@smallint_field"].Value = i;
command.Parameters["@float_field"].Value = (float)(i + 10) / 5;
command.Parameters["@double_field"].Value = Math.Log(i, 10);
command.Parameters["@numeric_field"].Value = (decimal)(i + 10) / 5;
command.Parameters["@date_field"].Value = DateTime.Now;
command.Parameters["@time_field"].Value = DateTime.Now;
command.Parameters["@timestamp_field"].Value = DateTime.Now;
command.Parameters["@clob_field"].Value = "IRow Number " + i.ToString();
command.Parameters["@blob_field"].Value = Encoding.Default.GetBytes("IRow Number " + i.ToString());
command.ExecuteNonQuery();
}
// Commit transaction
transaction.Commit();
}
catch (FbException)
{
transaction.Rollback();
throw;
}
finally
{
command.Dispose();
connection.Close();
}
}
示例2: ParameterDescribeTest
public void ParameterDescribeTest()
{
string sql = "insert into TEST (int_field) values (@value)";
FbCommand command = new FbCommand(sql, this.Connection);
command.Prepare();
command.Parameters.Add("@value", FbDbType.Integer).Value = 100000;
command.ExecuteNonQuery();
command.Dispose();
}
示例3: PrepareTest
public void PrepareTest()
{
// Create a new test table
FbCommand create = new FbCommand("create table PrepareTest(test_field varchar(20));", Connection);
create.ExecuteNonQuery();
create.Dispose();
// Insert data using a prepared statement
FbCommand command = new FbCommand(
"insert into PrepareTest(test_field) values(@test_field);",
Connection);
command.Parameters.Add("@test_field", FbDbType.VarChar).Value = DBNull.Value;
command.Prepare();
for (int i = 0; i < 5; i++)
{
if (i < 1)
{
command.Parameters[0].Value = DBNull.Value;
}
else
{
command.Parameters[0].Value = i.ToString();
}
command.ExecuteNonQuery();
}
command.Dispose();
try
{
// Check that data is correct
FbCommand select = new FbCommand("select * from PrepareTest", Connection);
FbDataReader reader = select.ExecuteReader();
int count = 0;
while (reader.Read())
{
if (count == 0)
{
Assert.AreEqual(DBNull.Value, reader[0], "Invalid value.");
}
else
{
Assert.AreEqual(count, reader.GetInt32(0), "Invalid value.");
}
count++;
}
reader.Close();
select.Dispose();
}
catch (Exception)
{
throw;
}
finally
{
// Drop table
FbCommand drop = new FbCommand("drop table PrepareTest", Connection);
drop.ExecuteNonQuery();
drop.Dispose();
}
}
示例4: ClearQuadruples
/// <summary>
/// Clears the quadruples of the store
/// </summary>
public override RDFStore ClearQuadruples() {
//Create command
var command = new FbCommand("DELETE FROM Quadruples", this.Connection);
try {
//Open connection
this.Connection.Open();
//Prepare command
command.Prepare();
//Open transaction
command.Transaction = this.Connection.BeginTransaction();
//Execute command
command.ExecuteNonQuery();
//Close transaction
command.Transaction.Commit();
//Close connection
this.Connection.Close();
}
catch (Exception ex) {
//Rollback transaction
command.Transaction.Rollback();
//Close connection
this.Connection.Close();
//Propagate exception
throw new RDFStoreException("Cannot delete data from Firebird store because: " + ex.Message, ex);
}
return this;
}
示例5: RemoveQuadruplesByLiteral
/// <summary>
/// Removes the quadruples with the given literal as object
/// </summary>
public override RDFStore RemoveQuadruplesByLiteral(RDFLiteral literalObject) {
if (literalObject != null) {
//Create command
var command = new FbCommand("DELETE FROM Quadruples WHERE ObjectID = @OBJID AND TripleFlavor = @TFV", this.Connection);
command.Parameters.Add(new FbParameter("OBJID", FbDbType.BigInt));
command.Parameters.Add(new FbParameter("TFV", FbDbType.Integer));
//Valorize parameters
command.Parameters["OBJID"].Value = literalObject.PatternMemberID;
command.Parameters["TFV"].Value = RDFModelEnums.RDFTripleFlavors.SPL;
try {
//Open connection
this.Connection.Open();
//Prepare command
command.Prepare();
//Open transaction
command.Transaction = this.Connection.BeginTransaction();
//Execute command
command.ExecuteNonQuery();
//Close transaction
command.Transaction.Commit();
//Close connection
this.Connection.Close();
}
catch (Exception ex) {
//Rollback transaction
command.Transaction.Rollback();
//Close connection
this.Connection.Close();
//Propagate exception
throw new RDFStoreException("Cannot delete data from Firebird store because: " + ex.Message, ex);
}
}
return this;
}
示例6: RemoveQuadruplesByPredicate
/// <summary>
/// Removes the quadruples with the given predicate
/// </summary>
public override RDFStore RemoveQuadruplesByPredicate(RDFResource predicateResource) {
if (predicateResource != null) {
//Create command
var command = new FbCommand("DELETE FROM Quadruples WHERE PredicateID = @PREDID", this.Connection);
command.Parameters.Add(new FbParameter("PREDID", FbDbType.BigInt));
//Valorize parameters
command.Parameters["PREDID"].Value = predicateResource.PatternMemberID;
try {
//Open connection
this.Connection.Open();
//Prepare command
command.Prepare();
//Open transaction
command.Transaction = this.Connection.BeginTransaction();
//Execute command
command.ExecuteNonQuery();
//Close transaction
command.Transaction.Commit();
//Close connection
this.Connection.Close();
}
catch (Exception ex) {
//Rollback transaction
command.Transaction.Rollback();
//Close connection
this.Connection.Close();
//Propagate exception
throw new RDFStoreException("Cannot delete data from Firebird store because: " + ex.Message, ex);
}
}
return this;
}
示例7: AddQuadruple
/// <summary>
/// Adds the given quadruple to the store, avoiding duplicate insertions
/// </summary>
public override RDFStore AddQuadruple(RDFQuadruple quadruple) {
if (quadruple != null) {
//Create command
var command = new FbCommand("UPDATE OR INSERT INTO Quadruples (QuadrupleID, TripleFlavor, Context, ContextID, Subject, SubjectID, Predicate, PredicateID, Object, ObjectID) VALUES (@QID, @TFV, @CTX, @CTXID, @SUBJ, @SUBJID, @PRED, @PREDID, @OBJ, @OBJID) MATCHING (QuadrupleID)", this.Connection);
command.Parameters.Add(new FbParameter("QID", FbDbType.BigInt));
command.Parameters.Add(new FbParameter("TFV", FbDbType.Integer));
command.Parameters.Add(new FbParameter("CTX", FbDbType.VarChar, 1000));
command.Parameters.Add(new FbParameter("CTXID", FbDbType.BigInt));
command.Parameters.Add(new FbParameter("SUBJ", FbDbType.VarChar, 1000));
command.Parameters.Add(new FbParameter("SUBJID", FbDbType.BigInt));
command.Parameters.Add(new FbParameter("PRED", FbDbType.VarChar, 1000));
command.Parameters.Add(new FbParameter("PREDID", FbDbType.BigInt));
command.Parameters.Add(new FbParameter("OBJ", FbDbType.VarChar, 5000));
command.Parameters.Add(new FbParameter("OBJID", FbDbType.BigInt));
//Valorize parameters
command.Parameters["QID"].Value = quadruple.QuadrupleID;
command.Parameters["TFV"].Value = quadruple.TripleFlavor;
command.Parameters["CTX"].Value = quadruple.Context.ToString();
command.Parameters["CTXID"].Value = quadruple.Context.PatternMemberID;
command.Parameters["SUBJ"].Value = quadruple.Subject.ToString();
command.Parameters["SUBJID"].Value = quadruple.Subject.PatternMemberID;
command.Parameters["PRED"].Value = quadruple.Predicate.ToString();
command.Parameters["PREDID"].Value = quadruple.Predicate.PatternMemberID;
command.Parameters["OBJ"].Value = quadruple.Object.ToString();
command.Parameters["OBJID"].Value = quadruple.Object.PatternMemberID;
try {
//Open connection
this.Connection.Open();
//Prepare command
command.Prepare();
//Open transaction
command.Transaction = this.Connection.BeginTransaction();
//Execute command
command.ExecuteNonQuery();
//Close transaction
command.Transaction.Commit();
//Close connection
this.Connection.Close();
}
catch (Exception ex) {
//Rollback transaction
command.Transaction.Rollback();
//Close connection
this.Connection.Close();
//Propagate exception
throw new RDFStoreException("Cannot insert data into Firebird store because: " + ex.Message, ex);
}
}
return this;
}