-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Serialized LOB Object output instead of content when object contains a LOB #1222
Comments
Given that the FORMATTED_DOC is a BLOB I would have expected a HexBinary representation of the LOB in the JSON object. |
That's a lot of text and I'm not sure what exactly you are trying to say. Can you create a test case that contains the table creation statement, insert statements to populate with data and the full code required to process it -- along with the output you expect and the output you are getting. Please make it as simple as possible so we don't have to wade through piles of text! Thanks. |
Anthony The SQL setup is the standard Oracle Sample Schemas. I thought that would make life simple The reason there is a lot of text in the output is that JSON.stringify has serialized the instance of the oracledb lob object class at the content of the attribute "FORMATTED_DOC'" rather than the contents of the LOB. In this case I would expect to see a HeXBinary representation of the content of the LOB as the value of "FORMATTTED_DOC", since the attribute is of type BLOB. If the attribute were of type CLOB then I would expect to see the contents of the CLOB. |
Ok. I don't use those sample schemas much myself! In any case, what I am seeing is that you are simply dumping the output of the call to connection.execute(). The LOB values are returned as LOB instances, not LOB data. You can use the fetchAsString and fetchAsBuffer options to retrieve the actual data in the result rather than LOB instances. If you want to use the LOB instances you'll need to use streaming reads to get the data. See the documentation on LOBs for more information. Instead of using JSON.stringify() which produces a nasty set of text which is hard for human beings to read, perhaps I can suggest you use this instead: |
Anthony I modified my code as follows
And I get this..
|
You're missing the equals sign in your code. You need this:
|
Sorry I missed that, but it makes no difference..
|
Can you try this example? This demonstrates the use of fetchAsString and fetchAsBuffer. If that works for you then you can find out what you did wrong. |
Anthony the scenario I am describing is different. In my case the LOB is an attribute of a PL/SQL Type, not a column in the database. If you look at the describe of the table the column I am fetching is AD_TEXTDOCS_NTAB PM.TEXTDOC_TAB Which is a PL/SQL Collection Type. The collection is defined as QL> desc PM.TEXTDOC_TAB DOCUMENT_TYP VARCHAR2(32) QL> So it is a collection on PM.TEXTDOC_TYP objects. Each TEXTDOC_TYP object has an attribute call FORMATTED_DOC of type BLOB. The error I am seeing is when I try to serialize the contents of D_TEXTDOCS_NTAB column... |
Ah! That makes more sense. Database objects are not affected by fetchAsString and fetchAsBuffer. You will need to get the data from the LOB yourself directly. Something like this:
There is no other way to deal with this at the moment. We are considering a means for returning the objects as plain JavaScript objects and expanding the LOB values directly, but have not implemented such yet. It can't be simply included in the object serialization as it requires a round trip to the database to get the data. |
Unfortunately since I am writing generic code that has to handle any object without knowing it's structure this is not really feasible in my particular use case. Combined with not yet supporting type hierarchies I'll have to roll my own PL/SQL based solution for the moment. |
Understoood. I'm going to mark this as an enhancement now that I actually understand what you were trying to do! |
It is worth considering whether conversion to JSON should not always be performed by runtime environment methods. For Node: import { json } from 'node:stream/consumers';
const data = await json( blob ); |
If you are referring to converting database objects to "pojo" (plain old javascript object), then that is already available. However, trying it with this scenario seems to indicate that the LOB values are not transformed -- which should be done, I think! Another enhancement to implement. :-) |
For some cases, the node-oracledb 6.0 fetch type handler converter functionality could be used. This would be easiest where the object structure is known in advance and your converter can directly fetch the LOB data using the attribute names like |
See https://www.oracle.com/corporate/security-practices/assurance/vulnerability/reporting.html for how to report security issues.
With the async/await programming style, make sure you are using 'await' in the right places.
Is it an error or a hang or a crash?
Error
What error(s) you are seeing?
Cut and paste text showing the command you ran. No screenshots. Use a gist for long screen output and logs: see https://gist.github.com/.
Incorrect output
Include a runnable Node.js script that shows the problem.
Include all SQL needed to create the database schema. Use Markdown syntax, see https://help.github.com/github/writing-on-github/basic-writing-and-formatting-syntax
C:\Development\YADAMU>
5. Run node and show the output of:
18,19,20
The text was updated successfully, but these errors were encountered: