GithubHelp home page GithubHelp logo

Comments (4)

kubo avatar kubo commented on July 21, 2024

I added StatementBuilder::lob_locator instead of Statement.define() in order to access LOBs as LOB locators.

I have not written enough documents about it. See Examples in Blob for now.

from rust-oracle.

daviessm avatar daviessm commented on July 21, 2024

I probably misunderstood something. My code is like this:

            //cursor is a ref_cursor containing multiple columns of different types
            for table_rows_result in cursor.query().unwrap() {
                let table_rows_result_row = table_rows_result.unwrap();
                let sql_values = table_rows_result_row.sql_values();
                for column in sql_values {
                    match column.oracle_type().unwrap() {
                        OracleType::Rowid => {
                            rowid = column.to_string();
                        }
                        OracleType::Varchar2(_)
                        | OracleType::NVarchar2(_)
                        | OracleType::Char(_)
                        | OracleType::NChar(_)
                        | OracleType::CLOB
                        | OracleType::NCLOB => match column.get::<String>() { //<- this is where I want to get the CLOBs as Strings without needing a second round trip to the database
                            Ok(val) => println!(val),
                            Err(e) => error!(
                                "Error {} getting string in {}.{} for row {}",
                                e, &table.owner, &table.name, &rowid
                            ),
                        },
                        //other column types are handled here
                        //[ ... ]
                        _ => {
                            error!(
                                "Unhandled Oracle type {} on table {}.{}, column {}",
                                column.oracle_type().unwrap(),
                                table.owner,
                                table.name,
                                _i
                            )
                        }
                    }
                }
            }

When the ref_cursor is polled, has OCI already buffered the CLOBs in memory and is returning them as pointers to the data without having to get the LOB pointer and request its contents from the database?

from rust-oracle.

kubo avatar kubo commented on July 21, 2024

I misunderstood your request.

LOB contents are fetched along with other column data by default since 0.5.3.

create table test_issue_43 (c1 varchar2(64), c2 clob, c3 varchar2(64));
insert into test_issue_43 values ('<AAAAAAAAAAAAAAAAAAAA>', '<BBBBBBBBBBBBBBBBBBBB>', '<CCCCCCCCCCCCCCCCCCCC>');
commit;
use oracle::sql_type::RefCursor;
use oracle::Connection;
use oracle::Result;

fn main() -> Result<()> {
    let username = "fix me";
    let password = "fix me";
    let database = "fix me";
    let sql = r#"
begin
  open :csr for select * from test_issue_43;
end;
"#;
    let conn = Connection::connect(username, password, database)?;
    let mut stmt = conn.statement(sql).build()?;
    stmt.execute(&[&None::<RefCursor>])?;
    let mut cursor: RefCursor = stmt.bind_value(1)?;
    for row_result in cursor.query_as::<(String, String, String)>()? {
        println!("row: {:?}", row_result?);
    }
    Ok(())
}

The following is captured data between Oracle client and server when the above program run. The LOB contents <BBBBBBBBBBBBBBBBBBBB> are in a packet along with varchar2 data.

21:18:54.086347 IP 172.17.0.2.1521 > 172.17.0.1.59552: Flags [P.], seq 3730:4069, ack 3252, win 501, options [nop,nop,TS val 1314153435 ecr 2147234727], length 339
	0x0000:  4500 0187 b8a4 4000 4006 28a7 ac11 0002  E.....@.@.(.....
	0x0010:  ac11 0001 05f1 e8a0 ea12 d926 4501 48e9  ...........&E.H.
	0x0020:  8018 01f5 599f 0000 0101 080a 4e54 63db  ....Y.......NTc.
	0x0030:  7ffc 33a7 0000 0153 0600 0000 0000 0601  ..3....S........
	0x0040:  2253 0300 0000 0000 6400 0000 0000 0000  "S......d.......
	0x0050:  0000 0000 0000 0000 0000 8101 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0716 3c41 4141 4141 4141 4141 4141 4141  ..<AAAAAAAAAAAAA
	0x0080:  4141 4141 4141 413e 163c 4242 4242 4242  AAAAAAA>.<BBBBBB
	0x0090:  4242 4242 4242 4242 4242 4242 4242 3e00  BBBBBBBBBBBBBB>.
	0x00a0:  0000 0016 3c43 4343 4343 4343 4343 4343  ....<CCCCCCCCCCC
	0x00b0:  4343 4343 4343 4343 433e 0806 0000 0000  CCCCCCCCC>......
	0x00c0:  0000 0000 0003 0000 0000 0000 0000 0000  ................
	0x00d0:  0000 0000 0000 0000 0000 0000 0004 0100  ................
	0x00e0:  0000 5b9f 0101 0000 007b 0500 0000 0003  ..[......{......
	0x00f0:  0000 0003 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0000 0000 0000 0000 0000 0000 0600  ................
	0x0110:  0000 0000 0036 0100 0000 0000 0000 0000  .....6..........
	0x0120:  0000 0000 00e0 b5a1 5453 7f00 0000 0000  ........TS......
	0x0130:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0140:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0150:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0160:  007b 0500 0001 0000 0000 0000 0019 4f52  .{............OR
	0x0170:  412d 3031 3430 333a 206e 6f20 6461 7461  A-01403:.no.data
	0x0180:  2066 6f75 6e64 0a                        .found.

When StatementBuilder::lob_locator is used, the LOB contents and varchar2 data are in different packets as follows.

23:06:32.067121 IP 172.17.0.2.1521 > 172.17.0.1.60970: Flags [P.], seq 3730:4173, ack 3252, win 501, options [nop,nop,TS val 1407011415 ecr 2240092688], length 443
	0x0000:  4500 01ef 46a2 4000 4006 9a41 ac11 0002  E...F.@[email protected]....
	0x0010:  ac11 0001 05f1 ee2a 5051 34a5 c932 1e64  .......*PQ4..2.d
	0x0020:  8018 01f5 5a07 0000 0101 080a 53dd 4a57  ....Z.......S.JW
	0x0030:  8585 1a10 0000 01bb 0600 0000 0000 0601  ................
	0x0040:  2293 0300 0000 0000 6400 0000 0000 0000  ".......d.......
	0x0050:  0000 0000 0000 0000 0000 8201 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0716 3c41 4141 4141 4141 4141 4141 4141  ..<AAAAAAAAAAAAA
	0x0080:  4141 4141 4141 413e 7200 0000 1600 0000  AAAAAAA>r.......
	0x0090:  0000 0000 7c1f 0000 7200 7000 0202 0c82  ....|...r.p.....
	0x00a0:  8000 0200 0000 0100 0002 b398 0e00 0141  ...............A
	0x00b0:  5800 0141 5700 0200 0203 6900 0000 0000  X..AW.....i.....
	0x00c0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x00d0:  0000 0000 00aa 0939 be00 0000 0000 00de  .......9........
	0x00e0:  adbe ef00 0100 2200 0000 0001 82c2 0d00  ......".........
	0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0141 5703 0006 a600 0016 3c43 4343  ...AW.......<CCC
	0x0110:  4343 4343 4343 4343 4343 4343 4343 4343  CCCCCCCCCCCCCCCC
	0x0120:  433e 0806 0000 0000 0000 0000 0002 0000  C>..............
	0x0130:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0140:  0000 0000 0004 0100 0000 1e0b 0101 0000  ................
	0x0150:  007b 0500 0000 0002 0000 0003 0000 0000  .{..............
	0x0160:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0170:  0000 0000 0000 0600 0000 0000 0036 0100  .............6..
	0x0180:  0000 0000 0000 0000 0000 0000 00e0 f5ff  ................
	0x0190:  29a3 7f00 0000 0000 0000 0000 0000 0000  )...............
	0x01a0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x01b0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x01c0:  0000 0000 0000 0000 007b 0500 0001 0000  .........{......
	0x01d0:  0000 0000 0019 4f52 412d 3031 3430 333a  ......ORA-01403:
	0x01e0:  206e 6f20 6461 7461 2066 6f75 6e64 0a    .no.data.found.

...

23:06:32.200815 IP 172.17.0.2.1521 > 172.17.0.1.60970: Flags [P.], seq 4184:4300, ack 3519, win 501, options [nop,nop,TS val 1407011549 ecr 2240092842], length 116
	0x0000:  4500 00a8 46a5 4000 4006 9b85 ac11 0002  E...F.@.@.......
	0x0010:  ac11 0001 05f1 ee2a 5051 366b c932 1f6f  .......*PQ6k.2.o
	0x0020:  8018 01f5 58c0 0000 0101 080a 53dd 4add  ....X.......S.J.
	0x0030:  8585 1aaa 0000 0048 0f20 0000 0000 0003  .......H........
	0x0040:  0000 002c 0000 0001 002c 0000 0000 0000  ...,.....,......
	0x0050:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0000 0000 0000 0000 0000 0000 003c 0042  .............<.B
	0x0080:  0042 0042 0042 0042 0042 0042 0042 0042  .B.B.B.B.B.B.B.B
	0x0090:  0042 0042 0042 0042 0042 0042 0042 0042  .B.B.B.B.B.B.B.B
	0x00a0:  0042 0042 0042 003e                      .B.B.B.>

Another way to fetch LOB contents in a packet along with other column data is combination of StatementBuilder::lob_locator and DefaultLobPrefetchSize. Use this only when you need to use oracle::sql_type::Clob, oracle::sql_type::Nclob or oracle::sql_type::Blob in order to read LOB contents by std::io::Read.

23:34:37.326294 IP 172.17.0.2.1521 > 172.17.0.1.33014: Flags [P.], seq 3730:4222, ack 3251, win 501, options [nop,nop,TS val 1408696675 ecr 2241777981], length 492
	0x0000:  4500 0220 2958 4000 4006 b75a ac11 0002  E...)X@[email protected]....
	0x0010:  ac11 0001 05f1 80f6 9e05 cd9d 0e8f 5af7  ..............Z.
	0x0020:  8018 01f5 5a38 0000 0101 080a 53f7 0163  ....Z8......S..c
	0x0030:  859e d13d 0000 01ec 0600 0000 0000 0601  ...=............
	0x0040:  22e3 0300 0000 0000 6400 0000 0000 0000  ".......d.......
	0x0050:  0000 0000 0000 0000 0000 8201 0000 0000  ................
	0x0060:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0070:  0716 3c41 4141 4141 4141 4141 4141 4141  ..<AAAAAAAAAAAAA
	0x0080:  4141 4141 4141 413e 7200 0000 1600 0000  AAAAAAA>r.......
	0x0090:  0000 0000 7c1f 0000 01d0 0701 2c00 3c00  ....|.......,.<.
	0x00a0:  4200 4200 4200 4200 4200 4200 4200 4200  B.B.B.B.B.B.B.B.
	0x00b0:  4200 4200 4200 4200 4200 4200 4200 4200  B.B.B.B.B.B.B.B.
	0x00c0:  4200 4200 4200 4200 3e72 0070 0002 020c  B.B.B.B.>r.p....
	0x00d0:  8280 0002 0000 0001 0000 02b3 980e 0001  ................
	0x00e0:  4158 0001 4157 0002 0002 0369 0000 0000  AX..AW.....i....
	0x00f0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0100:  0000 0000 0000 aa09 39be 0000 0000 0000  ........9.......
	0x0110:  dead beef 0001 0022 0000 0000 0182 c777  .......".......w
	0x0120:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0130:  0000 0001 4157 0300 06a6 0000 163c 4343  ....AW.......<CC
	0x0140:  4343 4343 4343 4343 4343 4343 4343 4343  CCCCCCCCCCCCCCCC
	0x0150:  4343 3e08 0600 0000 0000 0000 0000 0300  CC>.............
	0x0160:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x0170:  0000 0000 0000 0401 0000 0016 0c01 0100  ................
	0x0180:  0000 7b05 0000 0000 0300 0000 0300 0000  ..{.............
	0x0190:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x01a0:  0000 0000 0000 0006 0000 0000 0000 3601  ..............6.
	0x01b0:  0000 0000 0000 0000 0000 0000 0000 e045  ...............E
	0x01c0:  f1c8 e97f 0000 0000 0000 0000 0000 0000  ................
	0x01d0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x01e0:  0000 0000 0000 0000 0000 0000 0000 0000  ................
	0x01f0:  0000 0000 0000 0000 0000 7b05 0000 0100  ..........{.....
	0x0200:  0000 0000 0000 194f 5241 2d30 3134 3033  .......ORA-01403
	0x0210:  3a20 6e6f 2064 6174 6120 666f 756e 640a  :.no.data.found.

from rust-oracle.

daviessm avatar daviessm commented on July 21, 2024

Thanks, a misunderstanding on my part. It works fine. Next issue coming right up πŸ˜ƒ

from rust-oracle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.