# databaseManager.getDataSetByQuery() is creating bad query

**URL:** <https://forum.servoy.com/t/databasemanager-getdatasetbyquery-is-creating-bad-query/20038>\
**Category:** Classic Servoy\
**Created:** [July 17, 2019, 3:22am UTC](https://forum.servoy.com/t/databasemanager-getdatasetbyquery-is-creating-bad-query/20038 "2019-07-17T03:22:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![antonio](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@antonio](https://forum.servoy.com/u/antonio)\
**Post date:** [July 17, 2019, 3:22am UTC](https://forum.servoy.com/t/databasemanager-getdatasetbyquery-is-creating-bad-query/20038/1 "2019-07-17T03:22:16Z")

</div>

Hi Everyone. I am moving some functions from a servoy 5.x codebase to 8.x and I’m having issues with one of the three implementations of databaseManager.getDataSetByQuery (the implementation which takes a straight string as the query args being serverName: string, query: string, args: array, limit: int)

var query = 'select tenant.tenant\_id ’  
query += ‘FROM tenant, staff WHERE tenant.tenant\_id = staff.tenant\_id AND staff.is\_active = 1 AND tenant.is\_active = 1 ’  
query += ‘AND staff.user\_name = ?’  
query += ’ AND tenant.minor\_id = ?’;

var args = new Array();  
args[0] = fvUserName  
args[1] = fvSiteID

var dataset = databaseManager.getDataSetByQuery(‘cesoft’, query, args, 1);

When that query gets run I’m getting the following console error:

ERROR com.servoy.j2db.util.Debug - select tenant.tenant\_id FROM tenant, staff WHERE tenant.tenant\_id = staff.tenant\_id AND staff.is\_active = 1 AND tenant.is\_active = 1 AND staff.user\_name = ? AND tenant.minor\_id = ? parameters: [‘param1’ ,type: java.lang.String, ‘param2’ ,type: java.lang.String]  
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near **‘OPTION SQL\_SELECT\_LIMIT=2’** at line 1

I’m actually thinking this is a JDBC driver issue except for the fact that the LIMIT is being indexed automatically somewhere (note that the limit was set as 1 in the call to databaseManager, but the error above has LIMIT=2; in fact it’s always showing N+1 whatever limit N we use)

FYI this is the same DB and MySQL DB driver as I am using in 5.x  
I’ve tried both the org.gjt.mm.mysql.Driver and the com.mysql.jdbc.Driver

Any advice appreciated

---

<div class="post-metadata">

**Author:** ![antonio](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@antonio](https://forum.servoy.com/u/antonio)\
**Post date:** [July 17, 2019, 7:14am UTC](https://forum.servoy.com/t/databasemanager-getdatasetbyquery-is-creating-bad-query/20038/2 "2019-07-17T07:14:30Z")

</div>

Seems it _was_ a driver issue.

I upgraded from mysql-connector-java-5.1.7-bin.jar to mysql-connector-java-5.1.47-bin.jar and used the org.gjt.mm.mysql.Driver, no more MySQL error.  
This is with MySQL version 5.7.21
