You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use oracle::*;// oracle = "0.5.6"constCREATE_TEST_TABLE:&str = "CREATE TABLE test_table (\ text clob )";fnrepro(conn:Connection){let _ = conn.execute("DROP TABLE test_table",&[]);
conn.execute(CREATE_TEST_TABLE,&[]).unwrap();letmut 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",&None::<String>)]).unwrap();let s:&String = &stmt.returned_values("out1").unwrap()[0];assert_eq!(s,&long_text);}
I expect that this code passes without an error for a valid connection. Instead of that I get the following error message:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OciError(DbError { code: 22835, offset: 53, message: "ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 4000, maximum: 2000)", fn_name: "dpiStmt_execute", action: "execute" })', src/main.rs:16:10
(where line main.rs:16 refers to the unwrap after the execute_named)
The text was updated successfully, but these errors were encountered:
There are three ways. The second and third ones are usually unacceptable.
Use OracleType::CLOB in place of None::<String> and get the CLOB value as Clob.
Use OracleType::Varchar2(4000) in place of None::<String> if the maximum size of CLOB data is 4000.
Use 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_stringconstCREATE_TEST_TABLE:&str = "CREATE TABLE test_table (\ text clob )";fnrepro(conn:Connection){let _ = conn.execute("DROP TABLE test_table",&[]);
conn.execute(CREATE_TEST_TABLE,&[]).unwrap();letmut 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.htmlletmut clob:Clob = stmt.returned_values("out1").unwrap().remove(0);letmut 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
)The text was updated successfully, but these errors were encountered: