nhuanhoangduc / cu8-sequelize-oracle

MIT License
26 stars 24 forks source link

Can't create row with CLOB field larger than 4000 characters #2

Open myleftsock opened 7 years ago

myleftsock commented 7 years ago

Using Oracle, creating a new row in a table fails when the data assigned to a CLOB column is >4000 characters. The error is

SequelizeDatabaseError: ORA-01704: string literal too long

at module.exports.Query.run.Query.formatError (/apps/node-emc-data/node_modules/cu8-sequelize-oracle/lib/dialects/oracle/query.js:203:16)
at /apps/node-emc-data/node_modules/cu8-sequelize-oracle/lib/dialects/oracle/query.js:91:37
at custExecuteCb (/apps/node-emc-data/node_modules/oracledb/lib/connection.js:98:7)

The code looks like this:

                return schema.sequelize.transaction((t) => {
                    return schema.ApiEvents.create({
                        EVENT_TYPE: "wo",
                        EVENT_ACTION: uv.EVENT_COLLECTED == null || uv.EVENT_COLLECTED > uv.LAST_UPDATED ? "new" : "update",
                        EVENT_IN_DATE: schema.sequelize.literal("SYSDATE"),
                        EVENT_DATA: JSON.stringify(eventData),
                        EVENT_COMMENTS: null,
                        EVENT_COLLECTED: 0,
                        EVENT_ENGINEER: uv.E_ID,
                        EVENT_KEY: `${uv.WO_ID}-${uv.V_ID}`
                    }, { transaction: t }).then(() => {
                        return schema.Collected.create({
                            V_ID: uv.V_ID,
                            EVENT_COLLECTED: schema.sequelize.literal("SYSDATE")
                        }, { transaction: t });
                    });
                })

The model for the events table is as follows:

"use strict";

module.exports = function(sequelize, DataTypes) {
    var ApiEvents= sequelize.define("ApiEvents", 
        {
            EVENT_ID: { type: DataTypes.INTEGER, primaryKey: true },
            EVENT_TYPE: DataTypes.STRING,
            EVENT_ACTION: DataTypes.STRING,
            EVENT_IN_DATE: DataTypes.DATE,
            EVENT_OUT_DATE: DataTypes.DATE,
            EVENT_COLLECTED: DataTypes.INTEGER,
            EVENT_ENGINEER: DataTypes.STRING,
            EVENT_KEY: DataTypes.STRING,
            EVENT_DATA: DataTypes.TEXT,
            EVENT_COMMENTS: DataTypes.STRING,
            EVENT_HAZARDS: DataTypes.STRING,
        },
        {
            timestamps: true,
            createdAt: "EVENT_IN_DATE",
            updatedAt: "EVENT_OUT_DATE",
            tableName: "API_EVENTS",
            schema: "CALIGN",
            classMethods: {
                associate: function(models) {
                }
            }
        }
    );

    return ApiEvents;
};

The problem is the eventData, when stringified, is about 12,000 characters long, and could potentially be longer.

nhuanhoangduc commented 7 years ago

Sequelize .insertCLOB(model, req.body, 'ID', ['Field1_type_clob', 'Field2_type_clob'], function (err, result) { res.send(result); });