Open weiznich opened 1 year ago
There are three ways. The second and third ones are usually unacceptable.
OracleType::CLOB
in place of None::<String>
and get the CLOB value as Clob
.OracleType::Varchar2(4000)
in place of None::<String>
if the maximum size of CLOB data is 4000.OracleType::Varchar2(32767)
in place of None::<String>
and change the Oracle initialization parameter MAX_STRING_SIZE
to EXTENDED
if the maximum size of CLOB data is 32767. (I have not tested this...)use oracle::sql_type::{Clob, OracleType};
use oracle::Connection;
use std::io::Read; // for clob.read_to_string
const CREATE_TEST_TABLE: &str = "CREATE TABLE test_table (\
text clob
)";
fn repro(conn: Connection) {
let _ = conn.execute("DROP TABLE test_table", &[]);
conn.execute(CREATE_TEST_TABLE, &[]).unwrap();
let mut stmt = conn
.statement("INSERT INTO test_table(text) VALUES (:in1) RETURNING text INTO :out1")
.build()
.unwrap();
let long_text = std::iter::repeat('a').take(4000).collect::<String>();
stmt.execute_named(&[("in1", &long_text), ("out1", &OracleType::CLOB)])
.unwrap();
// https://docs.rs/oracle/latest/oracle/sql_type/struct.Clob.html
let mut clob: Clob = stmt.returned_values("out1").unwrap().remove(0);
let mut s = String::new();
clob.read_to_string(&mut s).unwrap();
assert_eq!(&s, &long_text);
}
Thanks for the fast answer. For context the real code casing this is coming from diesel-oci, so it's much more generic and cannot assume much about the actual fields. Solution 2 will not work there. Solution 1 works for CLOB
columns, but won't work if the user tries to load a VARCHAR
column (diesel-oci does currently not differentiate between these two types). Using the maximal-size variant sounds like it has some negative implications, is that correct?
I've tried the following code:
I expect that this code passes without an error for a valid connection. Instead of that I get the following error message:
(where line
main.rs:16
refers to the unwrap after theexecute_named
)