大对象应用
public static string filepath = "D:\\csharp_data\\data254.mp4";
//blob clob
public static int test_blob()
{
XuguConnection conn = new XuguConnection();
conn.ConnectionString = conn_xugu;
Try
{
conn.Open();
XuguCommand cmd = new XuguCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT COUNT(*) FROM USER_TABLES WHERE TABLE_NAME='TEST_BLOB'";
if (Convert.ToInt32(cmd.ExecuteScalar()) == 0)
{
cmd.CommandText = "CREATE TABLE TEST_BLOB(ID INT,SS BLOB)";
cmd.ExecuteNonQuery();
}
else
{
cmd.CommandText = "DROP TABLE TEST_BLOB";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE TABLE TEST_BLOB(ID INT,SS BLOB)";
cmd.ExecuteNonQuery();
}
cmd.CommandText = "INSERT INTO TEST_BLOB VALUES(1,NULL)";
cmd.ExecuteNonQuery();
cmd.CommandText = "UPDATE TEST_BLOB SET SS=? WHERE ID=1";
XuguBlob xb = new XuguBlob();
FileAccess acces = FileAccess.Read;
FileMode filemode = FileMode.Open;
long big_count = 0;
using (FileStream fs = new FileStream(filepath, filemode, acces))
{
byte[] b = new byte[64768];
Int64 amountRead = 0;
amountRead = fs.Read(b, 0, b.Length);
xb.BeginChunkWrite();
Int64 have_r = amountRead;
while (amountRead > 0)
{
big_count += amountRead;// count
have_r = have_r + b.Length;
xb.write(b, 0, (Int32)amountRead);
amountRead = fs.Read(b, 0, b.Length);
}
xb.EndChunkWrite();
}
cmd.Parameters.Add("?", XuguDbType.LongVarBinary, xb, ParameterDirection.Input);
cmd.ExecuteNonQuery();
xb.Close();
}
catch (Exception ei)
{
Console.WriteLine(ei.ToString());
}
finally
{
conn.Close();
Console.WriteLine("测试 关闭连接后 连接当前状态" + conn.State.ToString());
}
return 0;
}