Cubrid Study notes LOBs type data

Source: Internet
Author: User

    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.