Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amount of characters read by dpiLob_readBytes() #43

Closed
kubo opened this issue Oct 29, 2017 · 5 comments
Closed

amount of characters read by dpiLob_readBytes() #43

kubo opened this issue Oct 29, 2017 · 5 comments
Labels

Comments

@kubo
Copy link

kubo commented Oct 29, 2017

Is it guaranteed that dpiLob_readBytes() reads characters up to the specified amount if it doesn't reach the end of the LOB?
In other words, does the following code work? (Error checks are omitted for simplicity.)

    dpiLob *lob = ...;
    FILE *fp = ...;
    const uint64_t char_size = 8192;
    uint64_t byte_size;
    char *buf;
    uint64_t offset = 1;

    dpiLob_getBufferSize(lob, char_size, &byte_size);
    buf = malloc(byte_size);

    while (1) {
        uint64_t read_byte_len = byte_size;
        dpiLob_readBytes(lob, offset, char_size, buf, &read_byte_len);
        if (read_byte_len == 0) {
            break;
        }
        fwrite(buf, 1, read_byte_len, fp);
        offset += char_size;
    }

This assume that dpiLob_readBytes() always reads 8192 characters if it doesn't reach the end of the LOB. If this assumption is incorrect, could you change dpiLobReadBytes() or add a new function which returns the number of read characters as OCILobRead2() does? Otherwise, it must be counted in the caller to increment offset as follows.

        offset += number_of_characters_in_buf(buf, read_byte_len);
@anthony-tuininga
Copy link
Member

anthony-tuininga commented Oct 30, 2017

Provided the buffer size you provide is adequate to support the number of characters requested there should be no reason for a short read, but I'll confirm that by asking internally.

Note that OCI considers characters to be the same as UCS-2 codepoints. This is true in most cases, but for supplementary characters it is not and the numbers returned are inaccurate. You also have to take care not to split characters.

@kubo
Copy link
Author

kubo commented Oct 31, 2017

Thank you!
Low level functions such as read on unix and ReadFile on Windows succeed when more than one byte is read. They may return before specified amount of data arrive especially when they read packets from network. I know that high level functions tend to wait until all requested data arrive. However it isn't documented in the OCI manual about OCILobRead2(). If OCILobReads() didn't return the number of characters read, I didn't worry about it.

@anthony-tuininga
Copy link
Member

I have confirmed that OCI does not perform short reads, provided that there are sufficient characters available to read in the LOB and the provided buffer is sufficiently large to accept all of the characters requested. So your code you provided above should work just fine!

@kubo
Copy link
Author

kubo commented Oct 31, 2017

Thanks a lot and sorry for bothering you.

@anthony-tuininga
Copy link
Member

You're welcome. And you're not bothering me at all! You've been a tremendous help asking questions! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants