星空网 > 软件开发 > 数据库

CUBRID学习笔记 15 Lobs类型数据

  • BLOB: Binary large object
  • CLOB: Character large object 
  • 一个二进制 一个字符类型

 

  二进制的读取

CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);DbDataReader reader = cmd.ExecuteReader();while (reader.Read()){  CUBRIDBlob bImage = (CUBRIDBlob)reader[0];  byte[] bytes = new byte[(int)bImage.BlobLength];  bytes = bImage.getBytes(1, (int)bImage.BlobLength);  //...}


更新 clob类型
string sql = "UPDATE t SET c = ?";CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);CUBRIDClob Clob = new CUBRIDClob(conn);//Use the ConnectionString for testingstr = "server=localhost;database=demodb;port=33000;user=public;password="Clob.setString(1, str);CUBRIDParameter param = new CUBRIDParameter();param.ParameterName = "?";param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;param.Value = Clob;cmd.Parameters.Add(param);cmd.ExecuteNonQuery();

下面来看个完整的例子
using CUBRID.Data.CUBRIDClient;using System.Diagnostics;using System;using System.IO;using System.Data.Common;namespace LobExample{  class Program  {    private static void ExecuteSQL(string sql, CUBRIDConnection conn)    {      using (CUBRIDCommand cmd = new CUBRIDCommand(sql, conn))      {        cmd.ExecuteNonQuery();      }    }    private static void CreateTestTableLOB(CUBRIDConnection conn)    {      ExecuteSQL("drop table if exists t", conn);      ExecuteSQL("create table t(b BLOB, c CLOB)", conn);    }    private static void CleanupTestTableLOB(CUBRIDConnection conn)    {      ExecuteSQL("drop table if exists t", conn);    }    static void Main(string[] args)    {      CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder("localhost", "demodb", "public", "", "33000");      using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString()))      {        conn.Open();        CreateTestTableLOB(conn);        string sql = "insert into t (c) values(?)";        CUBRIDCommand cmd = new CUBRIDCommand(sql, conn);        CUBRIDClob Clob = new CUBRIDClob(conn);        String str = conn.ConnectionString;        StreamReader r = new StreamReader("test.txt");        string writestring = r.ReadToEnd();        r.Close();        Clob.setString(1, writestring);        CUBRIDParameter param = new CUBRIDParameter();        param.ParameterName = "?";        param.CUBRIDDataType = CUBRIDDataType.CCI_U_TYPE_CLOB;        param.Value = Clob;        cmd.Parameters.Add(param);        cmd.ExecuteNonQuery();        cmd.Close();        string sql2 = "SELECT c from t";        using (CUBRIDCommand cmd2 = new CUBRIDCommand(sql2, conn))        {          DbDataReader reader = cmd2.ExecuteReader();          while (reader.Read())          {            CUBRIDClob cImage = (CUBRIDClob)reader[0];            string str2 = cImage.getString(1, (int)cImage.ClobLength);            StreamWriter w = new StreamWriter("testout.txt");            w.Write(str2);            w.Close();            StreamReader r2 = new StreamReader("testout.txt");            string readstring = r2.ReadToEnd();            r2.Close();            Debug.Assert(writestring.Length == readstring.Length, "The inserted CLOB length is not valid!");            Debug.Assert(writestring.Equals(readstring), "The CLOB was not inserted correctly!");          }        }        CleanupTestTableLOB(conn);        conn.Close();      }    }  }}








原标题:CUBRID学习笔记 15 Lobs类型数据

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

海狐海淘:https://www.goluckyvip.com/tag/32654.html
海欢网:https://www.goluckyvip.com/tag/32655.html
海卡fba:https://www.goluckyvip.com/tag/32656.html
海客信使:https://www.goluckyvip.com/tag/32657.html
海空网:https://www.goluckyvip.com/tag/32658.html
FBA热销SKU:https://www.goluckyvip.com/tag/3266.html
资金尚未冻结!又是国人原告!国民品牌也发起tro!支架专利来袭!:https://www.kjdsnews.com/a/1842120.html
在后第三方cookie时代,如何有效测量营销活动效果?:https://www.kjdsnews.com/a/1842121.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流