- Blob:binary Large Object
- Clob:character Large Object
- A binary one character type
Binary Read
Cubridcommand cmd = new Cubridcommand (SQL, conn);D bdatareader 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); //...}
Update CLOB type
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 ();p Aram. ParameterName = "?"; Param. Cubriddatatype = Cubriddatatype.cci_u_type_clob;param. Value = Clob;cmd. Parameters.Add (param); cmd. ExecuteNonQuery ();
Let's take a look at a complete example.
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 Exis TS T ", conn); } static void Main (string[] args) {Cubridconnectionstringbuilder sb = new cubridconnectionstring Builder ("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 is not inserted correctly!"); }} CLEANUPTESTTABLELOB (conn); Conn. Close (); } } }}
Cubrid Study notes LOBs type data