Announcement

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

    Server-side DSRequest criteria discrepancies

    Using SmartGWTPro 4.0:

    I'm developing a server-side standalone app to accompany our webapp. My standalone datasources have been fine up until today when this code:

    Code:
    DSRequest dsReq = new DSRequest("drivesafe3", "update");
    			Map criteria = new HashMap();
    			criteria.put("DriveSafe3ID", unitID);
    			Map values = new HashMap();
    			values.put("DS3IP", unitIP);
    			dsReq.setCriteria(criteria);
    			dsReq.setValues(values);
    			dsReq.execute();
    would produce this SQL query:

    === 2013-11-07 23:01:40,959 [er-1] INFO SQLDriver - [builtinApplication.null] Executing SQL update on 'Mysql': UPDATE drivesafe3 SET DS3IP='173.135.113.153:8080' WHERE (drivesafe3.DriveSafe3ID=23)


    whereas this code:

    Code:
    DSRequest request = new DSRequest("data_record", "update");
    			Map dataRecord = new HashMap();
    			dataRecord.put("LastKnownDate", lastDate);
    			dataRecord.put("LastKnownHour", lastHour);
    			dataRecord.put("LastKnownEventID", lastEventID);
    			dataRecord.put("LastKnownTelemetryID", lastTelID);
    			request.setCriteria("DeviceID", unitID);
    			request.setValues(dataRecord);
    			request.execute();
    produces this SQL query:

    === 2013-11-07 23:00:40,748 [er-2] INFO SQLDriver - [builtinApplication.null] Executing SQL update on 'Mysql': UPDATE data_record SET LastKnownDate='11_08_2013', LastKnownEventID=0, LastKnownHour='03', LastKnownTelemetryID=1 WHERE ('1'='1')


    Notice the criteria successfully appears as part of the generated SQL script with the first example, but not with the second.

    I have tried several methods of setting the criteria (setCriteria() with a map and with a key/value pair, addToCriteria()), and it never seems to "stick". Elsewhere in the code, I'm able to successfully fetch from this datasource using criteria, but I can't seem to update.

    What am I missing here???

    #2
    Most likely, you have misspelled or mis-capitalized DeviceID such that it doesn't match the name of your DataSourceField. That, or the field is not declared as primaryKey="true".

    Comment


      #3
      Thanks for you response! Unfortunately, I don't think typos are my problem. My datasources are very simple for this app; they specify a primary key and otherwise are autoderived from the MySQL tables. DeviceID is not a primary key for this datasource; it's just one column that I want to use to find a specific row in the table. When fetching from this same datasource, I can set DeviceID in the criteria, and it fetches the correct row - I just can't update. Or rather, because the criteria is not "sticking" my update operation updates every row in the table, which isn't exactly helpful. (Incidentally, I did try updating using the actual primary key for this datasource, and that didn't work either.)

      I also get the following error every time I try to update just the faulty datasource:

      Code:
      === 2013-11-08 14:54:32,570 [er-7] ERROR DataSource - [builtinApplication.null] Autogenerated audit is available only for Enterprise licenses.
      Unfortunately it doesn't help me very much as I've only got the Pro license, plus I don't really see what I could change being that the datasource descriptor is so simple.

      I'm happy to provide any more logs/code, I'm just not even sure what to show that would be relevant in this case.

      Comment


        #4
        DeviceID is not a primary key for this datasource
        This is the problem. Set allowMultiUpdate to do updates that do not involve the primaryKey.

        Comment

        Working...
        X