Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Cannot use commas in text fields when `multipleStorage` is set to `json`

    I have a SQLDataSource that stores a multiple:true field as JSON. It works fine with numbers, but fails when I use strings with commas - SmartClient always splits/trims values on comma, whether parsing data from client or reading stored values from the database.

    Database schema (PostgreSQL):
    Code:
    CREATE TABLE test_json_comma (
      id SERIAL PRIMARY KEY,
      some_values jsonb DEFAULT '[]'::jsonb
    );
    INSERT INTO test_json_comma (some_values) VALUES ('["11,22", "33"]'::jsonb);
    Data source:
    Code:
    <DataSource ID="testJsonCommaDS" serverType="sql" tableName="test_json_comma">
        <fields>
            <field name="id" type="sequence" hidden="true" primaryKey="true"/>
            <field name="some_values" type="text" multiple="true" multipleStorage="json"/>
        </fields>
    </DataSource>
    Test cases:

    1. Read values are split and mangled when reading from the database
    Code:
    > testJsonCommaDS.fetchData({id: 1}, (_, data) => console.log(data[0].some_values))
    ["1", "2", "33"]
    // should have been ["11,22", "33"]
    2. Server error when using "," at the end or beginning if value:
    Code:
    testJsonCommaDS.addData({some_values:["1,2", "3,"]})
    Log:
    Code:
    15:31:43.133 INFO [admin][web-176] com.isomorphic.datasource.DSRequest : Executing testJsonCommaDS.add with
    criteria: {}
    values: {
        some_values:["1,2", "3,"]
    }
    15:31:43.137 INFO [admin][web-176] com.isomorphic.SQL : Executing SQL query on 'X': INSERT INTO test_json_comma (some_values, id) VALUES ('["1,2","3,"]', nextval('test_json_comma_id_seq'))
    15:31:43.139 INFO [admin][web-176] com.isomorphic.datasource.DSRequest : Switching cacheSyncTiming to 'immediate' because this is a client 'add' request (dataSource is 'testJsonCommaDS')
    15:31:43.139 INFO [admin][web-176] com.isomorphic.SQL : Executing SQL query on 'X': SELECT currval('test_json_comma_id_seq')
    15:31:43.140 INFO [admin][web-176] com.isomorphic.datasource.DSRequest : primaryKeys: {id=6}
    15:31:43.141 INFO [admin][web-176] com.isomorphic.datasource.DSRequest : Executing testJsonCommaDS.fetch rows: 0->-1 with
    criteria: {id:6}
    15:31:43.147 INFO [admin][web-176] com.isomorphic.SQL : 52: Executing cache sync query on 'X': SELECT test_json_comma.id, test_json_comma.some_values FROM test_json_comma WHERE (test_json_comma.id=6) ORDER BY test_json_comma.id OFFSET 0 LIMIT 1
    15:31:43.149 WARN [admin][web-176] com.isomorphic.servlet.RequestContext : dsRequest.execute() failed:
    
    java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 1
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606)
        at java.base/java.lang.String.substring(String.java:2709)
        at com.isomorphic.datasource.BasicDataSource.convertFromSchemaValue(BasicDataSource.java:4547)
        at com.isomorphic.datasource.BasicDataSource.transformMultipleFields(BasicDataSource.java:4697)
        at com.isomorphic.datasource.DataSource.execute(DataSource.java:3368)
        at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:656)
        at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:555)
        at com.isomorphic.application.AppBase.execute(AppBase.java:498)
        at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:4803)
        at com.isomorphic.sql.cachesync.SQLRefetchStrategy.getCacheSyncData(SQLRefetchStrategy.java:118)
        at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:2204)
        at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1820)
        at com.isomorphic.sql.SQLDataSource.processRequest(SQLDataSource.java:509)
        at com.isomorphic.sql.SQLDataSource.executeAdd(SQLDataSource.java:461)
        at com.isomorphic.datasource.DataSource.execute(DataSource.java:3371)
        at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:656)
        at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:555)
        at com.isomorphic.application.AppBase.execute(AppBase.java:498)
        at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:4803)
        at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:255)
    SmartClient version: v13.1p_2025-07-01/PowerEdition Deployment

    #2
    Have you seen the doc for DataSourceField.multipleStorageSeparator/multipleValueSeparator?

    Comment


      #3
      Yes, and the documentation you linked shouldn't apply to "json" storage:
      the separator used in the "simpleString" MultipleFieldStorage mode.
      But just to be sure, I changed my example to:
      Code:
      <field name="some_values" type="text" multiple="true" multipleStorage="json"
             multipleStorageSeparator="?" multipleValueSeparator="?"/>
      and nothing changed. Data is still mangled on read, and the same exception is thrown on write.

      Comment


        #4
        Hi, can you look into that? The documentation you linked doesn't apply here, and using multipleValueSeparator doesn't help.

        Comment


          #5
          We have already investigated and resolved this on the 15.0 branch - change was committed yesterday. Please let us know which version you are using.

          Comment


            #6
            Thanks. It would be ideal if you could apply the fix to 13.0, but I'm in the process of updating to 13.1, so that would also work for me.

            Comment


              #7
              OK, we have backported it as far as 13.0, so the fix will be present in 13.0 and greater as of tomorrow's builds (those dated July 23)

              Comment

              Working...
              X