Announcement

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

    BooleanItem for an integer field?

    My MySQL database has a field 'enabled' that is defined as an int (actually a tinyint) but is used as a boolean. I want to display this with a BooleanItem but don't see how to do the conversion.

    Can BooleanItem front an integer field?

    --- from ds.xml --------------
    <field name="enabled" type="integer"/>

    --- from client code --------
    BooleanItem enabledFld = new BooleanItem("enabled");

    (SmartGWT 2.5)

    thanks!
    chris

    #2
    Declare it type "boolean" in your DataSource and see dataSourceField.sqlStorageStategy.
    Last edited by Isomorphic; 19 Sep 2011, 14:47.

    Comment


      #3
      After reading SmartClient_Reference.html#attr..DataSourceField.sqlStorageStrategy I tried this...

      <field name="enabled" type="boolean" sqlStorageStrategy="integer"/>

      But false and true still both store as '1'. And the ListGrid shows all the rows disabled (greyed out and not selectable). There aren't any errors or warnings in the logs.

      Just for clarity, I've got a BooleanItem backed by the above ds.xml field and a database schema defining the field as tiniyint.

      ???
      chris

      Comment


        #4
        You've probably still go some other logic involved. Try just a manual programmatic DataSource.updateData() call and you should be able to verify the feature is working fine. If you're still having trouble, show the complete server-side logs for a request that seems to be executed incorrectly, including the data delivered to the browser as shown in the RPC tab of the Developer Console.

        Comment


          #5
          I was getting '1' in my database because the schema defaults to
          1 and since my BooleanItem was not explicitly set to 'false' there schema default kicked in. So I made my BooleanItem explicitly 'false' and that part works.

          BooleanItem enabledFld = new BooleanItem("enabled");
          form.setValue("enabled", false);

          But the grid still shows all the rows as disabled. I expect this is because my 'enabled' field is in conflict with something SmartGWT uses to determine if a row is 'enabled'. Sound right?

          If that is right then how can I get around the 'enabled' naming conflict if I cannot change my database schema?

          Comment


            #6
            Never mind my last post. I need to use 'nativeName' as described in SmartClient_Reference.html#attr..DataSourceField.nativeName

            sorry for the noise,
            chris

            Comment


              #7
              That's one approach, another is to use setRecordEnabledProperty.

              "enabled" is one of several properties you can set on ListGrid records to influence behavior from data, all of which can be re-named if there's a conflict.

              Comment


                #8
                (In honor of International Talk Like A Pirate Day...) Aaarrrrgh! Me SQL and ISC Responses Arrrgh not well. Blast! and Arrrrghhh! Matey!

                Notice how the SQL query returns ruleEnabled:'1' but the isc response has ruleEnabled:false

                The documentation for sqlStorageStrategy states that 0 is false and 1 is true. I've tested setting the BooleanItem to true and the database gets 1 but the isc response has false. I've also tested setting the BooleanItem to false and the database gets 0 but the isc response has false anyway. The same snippets below are for when I set the 'ruleEnabled' field 'true'.

                I'm at a loss here because I have no DMI or other code that affects the value other than what is shown below.

                #--- UI form ------------------------------------------------------------------------
                Code:
                BooleanItem enabledFld = new BooleanItem("ruleEnabled");
                enabledFld.setValue(false);
                #--- ds.xml -------------------------------------------------------------------------
                Code:
                <field name="ruleEnabled" nativeName="enabled" title="Enabled" type="boolean" sqlStorageStrategy="integer"/>
                #--- 'add' creates this SQL ---------------------------------------------------------
                Code:
                INSERT INTO SomeRule (description, name, enabled) VALUES ('XXXXX', 'XXXXXX', 1)
                #--- 'fetch' creates this SQL --------------------------------------------------------
                Code:
                SELECT SomeRule.id, SomeRule.description, SomeRule.name, SomeRule.enabled AS ruleEnabled FROM SomeRule WHERE (SomeRule.id='7')
                #--- That SQL shows this in my database console client ------------------------------
                Code:
                +----+-------------+--------+-------------+
                | id | description | name   | ruleEnabled |
                +----+-------------+--------+-------------+
                |  7 | XXXXX       | XXXXXX |           1 |
                +----+-------------+--------+-------------+
                #--- FireBug shows this is the response. ---------------------------------------------
                Code:
                //isc_RPCResponseStart-->[{queueStatus:0,isDSResponse:true,invalidateCache:false,status:0,data:[{id:6,name:"ASASAA",ruleEnabled:false}]}]//isc_RPCResponseEnd
                #--- Server log for 'add' -----------------------------------------------------------
                Code:
                === 2011-09-19 15:04:43,021 [0-13] INFO  RequestContext - URL: '/iapp/sc/IDACall', User-Agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': Moz (Gecko) with Accept-Encoding header
                === 2011-09-19 15:04:43,024 [0-13] DEBUG XML - Parsed XML from (in memory stream): 2ms
                === 2011-09-19 15:04:43,026 [0-13] DEBUG RPCManager - Processing 1 requests.
                === 2011-09-19 15:04:43,027 [0-13] DEBUG RPCManager - Request #1 (DSRequest) payload: {
                    values:{
                        description:"XXXXX",
                        name:"XXXXXX",
                        ruleEnabled:true
                    },
                    operationConfig:{
                        dataSource:"SomeRule",
                        operationType:"add"
                    },
                    appID:"builtinApplication",
                    operation:"SomeRule_add",
                    oldValues:{
                        description:"XXXXX",
                        name:"XXXXXX",
                        ruleEnabled:true
                    },
                    criteria:{
                    }
                }
                === 2011-09-19 15:04:43,027 [0-13] INFO  IDACall - Performing 1 operation(s)
                === 2011-09-19 15:04:43,028 [0-13] DEBUG AppBase - [builtinApplication.SomeRule_add] No userTypes defined, allowing anyone access to all operations for this application
                === 2011-09-19 15:04:43,028 [0-13] DEBUG AppBase - [builtinApplication.SomeRule_add] No public zero-argument method named '_SomeRule_add' found, performing generic datasource operation
                === 2011-09-19 15:04:43,028 [0-13] INFO  SQLDataSource - [builtinApplication.SomeRule_add] Performing add operation with
                	criteria: {}	values: {description:"XXXXX",name:"XXXXXX",ruleEnabled:true}
                === 2011-09-19 15:04:43,029 [0-13] DEBUG SQLValuesClause - [builtinApplication.SomeRule_add] Sequences: {}
                === 2011-09-19 15:04:43,085 [0-13] DEBUG PoolableSQLConnectionFactory - [builtinApplication.SomeRule_add] Returning pooled Connection
                === 2011-09-19 15:04:43,085 [0-13] DEBUG SQLTransaction - [builtinApplication.SomeRule_add] Started new Mysql transaction "1286744655"
                === 2011-09-19 15:04:43,085 [0-13] INFO  SQLDriver - [builtinApplication.SomeRule_add] Executing SQL update on 'Mysql': INSERT INTO SomeRule (description, name, enabled) VALUES ('XXXXX', 'XXXXXX', 1)
                === 2011-09-19 15:04:43,086 [0-13] DEBUG SQLDataSource - [builtinApplication.SomeRule_add] add operation affected 1 rows
                === 2011-09-19 15:04:43,086 [0-13] DEBUG MysqlDriver - [builtinApplication.SomeRule_add] fetchLastRow data - primaryKeysPresent: {}sequencesNotPresent: [id]
                === 2011-09-19 15:04:43,086 [0-13] INFO  SQLDriver - [builtinApplication.SomeRule_add] Executing SQL query on 'Mysql': SELECT LAST_INSERT_ID()
                === 2011-09-19 15:04:43,087 [0-13] INFO  SQLDataSource - [builtinApplication.SomeRule_add] primaryKeys: {id=7}
                === 2011-09-19 15:04:43,087 [0-13] INFO  SQLDriver - [builtinApplication.SomeRule_add] Executing SQL query on 'Mysql': SELECT SomeRule.id, SomeRule.description, SomeRule.name, SomeRule.enabled AS ruleEnabled FROM SomeRule WHERE (SomeRule.id='7')
                === 2011-09-19 15:04:43,089 [0-13] INFO  DSResponse - [builtinApplication.SomeRule_add] DSResponse: List with 1 items
                === 2011-09-19 15:04:43,089 [0-13] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
                === 2011-09-19 15:04:43,089 [0-13] DEBUG SQLTransaction - Committing Mysql transaction "1286744655"
                === 2011-09-19 15:04:43,197 [0-13] DEBUG SQLTransaction - Ending Mysql transaction "1286744655"
                === 2011-09-19 15:04:43,219 [0-13] DEBUG RPCManager - non-DMI response, dropExtraFields: false
                === 2011-09-19 15:04:43,220 [0-13] INFO  Compression - /iapp/sc/IDACall: 238 -> 180 bytes
                #--- Server log for 'fetch' -----------------------------------------------------------
                Code:
                === 2011-09-19 15:04:43,021 [0-13] INFO  RequestContext - URL: '/iapp/sc/IDACall', User-Agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': Moz (Gecko) with Accept-Encoding header
                === 2011-09-19 15:04:43,024 [0-13] DEBUG XML - Parsed XML from (in memory stream): 2ms
                === 2011-09-19 15:04:43,026 [0-13] DEBUG RPCManager - Processing 1 requests.
                === 2011-09-19 15:04:43,027 [0-13] DEBUG RPCManager - Request #1 (DSRequest) payload: {
                    values:{
                        description:"XXXXX",
                        name:"XXXXXX",
                        ruleEnabled:true
                    },
                    operationConfig:{
                        dataSource:"SomeRule",
                        operationType:"add"
                    },
                    appID:"builtinApplication",
                    operation:"SomeRule_add",
                    oldValues:{
                        description:"XXXXX",
                        name:"XXXXXX",
                        ruleEnabled:true
                    },
                    criteria:{
                    }
                }
                === 2011-09-19 15:04:43,027 [0-13] INFO  IDACall - Performing 1 operation(s)
                === 2011-09-19 15:04:43,028 [0-13] DEBUG AppBase - [builtinApplication.SomeRule_add] No userTypes defined, allowing anyone access to all operations for this application
                === 2011-09-19 15:04:43,028 [0-13] DEBUG AppBase - [builtinApplication.SomeRule_add] No public zero-argument method named '_SomeRule_add' found, performing generic datasource operation
                === 2011-09-19 15:04:43,028 [0-13] INFO  SQLDataSource - [builtinApplication.SomeRule_add] Performing add operation with
                	criteria: {}	values: {description:"XXXXX",name:"XXXXXX",ruleEnabled:true}
                === 2011-09-19 15:04:43,029 [0-13] DEBUG SQLValuesClause - [builtinApplication.SomeRule_add] Sequences: {}
                === 2011-09-19 15:04:43,085 [0-13] DEBUG PoolableSQLConnectionFactory - [builtinApplication.SomeRule_add] Returning pooled Connection
                === 2011-09-19 15:04:43,085 [0-13] DEBUG SQLTransaction - [builtinApplication.SomeRule_add] Started new Mysql transaction "1286744655"
                === 2011-09-19 15:04:43,085 [0-13] INFO  SQLDriver - [builtinApplication.SomeRule_add] Executing SQL update on 'Mysql': INSERT INTO SomeRule (description, name, enabled) VALUES ('XXXXX', 'XXXXXX', 1)
                === 2011-09-19 15:04:43,086 [0-13] DEBUG SQLDataSource - [builtinApplication.SomeRule_add] add operation affected 1 rows
                === 2011-09-19 15:04:43,086 [0-13] DEBUG MysqlDriver - [builtinApplication.SomeRule_add] fetchLastRow data - primaryKeysPresent: {}sequencesNotPresent: [id]
                === 2011-09-19 15:04:43,086 [0-13] INFO  SQLDriver - [builtinApplication.SomeRule_add] Executing SQL query on 'Mysql': SELECT LAST_INSERT_ID()
                === 2011-09-19 15:04:43,087 [0-13] INFO  SQLDataSource - [builtinApplication.SomeRule_add] primaryKeys: {id=7}
                === 2011-09-19 15:04:43,087 [0-13] INFO  SQLDriver - [builtinApplication.SomeRule_add] Executing SQL query on 'Mysql': SELECT SomeRule.id, SomeRule.description, SomeRule.name, SomeRule.enabled AS ruleEnabled FROM SomeRule WHERE (SomeRule.id='7')
                === 2011-09-19 15:04:43,089 [0-13] INFO  DSResponse - [builtinApplication.SomeRule_add] DSResponse: List with 1 items
                === 2011-09-19 15:04:43,089 [0-13] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
                === 2011-09-19 15:04:43,089 [0-13] DEBUG SQLTransaction - Committing Mysql transaction "1286744655"
                === 2011-09-19 15:04:43,197 [0-13] DEBUG SQLTransaction - Ending Mysql transaction "1286744655"
                === 2011-09-19 15:04:43,219 [0-13] DEBUG RPCManager - non-DMI response, dropExtraFields: false
                === 2011-09-19 15:04:43,220 [0-13] INFO  Compression - /iapp/sc/IDACall: 238 -> 180 bytes

                Comment


                  #9
                  Aaarrrrgh! What JDBC driver be this?

                  Seriously.. we are doing basically..

                  Code:
                  Object obj = resultSet.getObject(columnNumber);
                  obj = "1".equals(obj.toString()) ? Boolean.TRUE : Boolean.FALSE;
                  So your results suggest that your particular combo of JDBC driver and MySQL build are taking the value of "1" for a TINYINT column and providing a string other than "1" when looked at via the JDBC driver. Can you try a standalone test and see if indeed that's happening?

                  Comment


                    #10
                    Thanks for the pointer to setRecordEnabledProperty. I like that approach better. It's less pervasive.

                    But I still get the same results as in my last post.
                    ,chris

                    Comment


                      #11
                      P-( ... Me frown is pirateee! (OK, not more pirate refs, I promise)

                      Here's my server.properties for the database.

                      Code:
                      #sql.Mysql.driver.driverType: thin
                      sql.Mysql.driver.user: myapp
                      sql.Mysql.database.type: mysql
                      sql.Mysql.driver.serverName: localhost
                      sql.Mysql.driver.useUnicode: true
                      sql.Mysql.database.ansiMode: false
                      sql.Mysql.pool.enabled: true
                      sql.Mysql.interface.credentialsInURL: true
                      #sql.Mysql.driver.networkProtocol: tcp
                      sql.Mysql.driver.password: changeme
                      sql.Mysql.driver.databaseName: myapp
                      sql.Mysql.driver: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
                      sql.Mysql.driver.portNumber: 3306
                      sql.Mysql.interface.type: dataSource

                      Comment


                        #12
                        Should have mentioned:
                        MySQL version: Ver 14.14 Distrib 5.5.14, for osx10.6 (i386) using readline 5.1

                        And I did notice that other integer types are are single-quoted in the SQL e.g.,

                        Code:
                        UPDATE SomeTbl SET enabled=1, someIntegerValue='2' WHERE (SomeTbl.id='9')
                        Not sure why the single quotes happen or not based on your code. ... I think your code was for the SELECT phase anyway, not the INSERT or UPDATE, right?
                        ,chris

                        Comment


                          #13
                          This is interesting.

                          The sql script creates the field like this... (notice the DEFAULT true)
                          Code:
                          `enabled` TINYINT(1)  NOT NULL DEFAULT true
                          The MySQL docs say JDBC would consider that setup as a boolean: http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-type-conversions.html

                          So I changed my ds.xml back to
                          Code:
                          <field name="enabled" type="boolean"/>
                          Which results in this SQL. It works fine when used in the mysql command line client but fails in my SmartClient app.
                          Code:
                          UPDATE SomeRule SET enabled='true' WHERE (SomeRule.id='10')
                          Here's the stack-trace...
                          Code:
                          === 2011-09-19 17:37:02,146 [l0-7] WARN  RequestContext - dsRequest.execute() failed: 
                          java.sql.SQLException: Incorrect integer value: 'true' for column 'enabled' at row 1
                          	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
                          	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3603)
                          	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3535)
                          	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1989)
                          	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2150)
                          	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2626)
                          	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
                          	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415)
                          	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2333)
                          	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2318)
                          	at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
                          	at com.isomorphic.sql.SQLDriver.doUpdate(SQLDriver.java:461)
                          	at com.isomorphic.sql.SQLDriver.update(SQLDriver.java:415)
                          	at com.isomorphic.sql.SQLDriver.executeUpdate(SQLDriver.java:535)
                          	at com.isomorphic.sql.SQLDataSource.executeNativeUpdate(SQLDataSource.java:387)
                          	at com.isomorphic.sql.SQLDataSource.SQLExecute(SQLDataSource.java:1338)
                          	at com.isomorphic.sql.SQLDataSource.processRequest(SQLDataSource.java:280)
                          	at com.isomorphic.sql.SQLDataSource.executeUpdate(SQLDataSource.java:228)
                          	at com.isomorphic.datasource.DataSource.execute(DataSource.java:1054)
                          	at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:721)
                          	at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
                          	at com.isomorphic.application.AppBase.execute(AppBase.java:491)
                          	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:1443)
                          	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:173)
                          	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:130)
                          	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:95)
                          	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
                          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
                          	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
                          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                          	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
                          	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
                          	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:259)
                          	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
                          	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
                          	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
                          	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
                          	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
                          	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
                          	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
                          	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
                          	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
                          	at org.mortbay.jetty.Server.handle(Server.java:324)
                          	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
                          	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
                          	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
                          	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
                          	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
                          	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
                          	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

                          Comment


                            #14
                            Originally posted by Isomorphic
                            ...your results suggest that your particular combo of JDBC driver and MySQL build are taking the value of "1" for a TINYINT column and providing a string other than "1" when looked at via the JDBC driver. Can you try a standalone test and see if indeed that's happening?
                            Did my last posts answer this? Or are you looking for some other form of test?

                            ,chris

                            Comment


                              #15
                              We were asking if you could try a straight JDBC test and see what your driver is returning. Should be just a few lines of code, and we can't easily reproduce your complete environment nor are we sure which details matter.

                              Comment

                              Working...
                              X