Book a Demo

Author Topic: SqlQuery: Different behaviour when access DB Vs a  (Read 2994 times)

derekwallace

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
SqlQuery: Different behaviour when access DB Vs a
« on: August 23, 2012, 08:04:12 pm »
Hi,
We host our EA models in a MySQL DB.
I have created a shortcut .eap file to the DB.

When i run a Java program to perform a SqlQuery of the DB (via the shortcut .eap) file it works correctly.

org.sparx.Repository oRepos = new org.sparx.Repository()
oRepos.OpenFile(sReposName);

String sSqlQuery  = "SELECT t_object.ea_guid AS GUID  FROM t_object";
String sTmp = oRepos.SQLQuery(sSqlQuery);
System.out.println(sTmp);




If i "transfer" the DB to a .eap project (to create a local copy) with the
Tools - Data Management - Project Transfer
and re-run the same JAVA program to do a SqlQuery it returns the following with no data.
<?xml version="1.0"?>
<EADATA version="1.0" exporter="Enterprise Architect">
</EADATA>



Does the SQL query need to change depending on the database behind the scenes?

Thx
Derek


« Last Edit: August 23, 2012, 08:11:49 pm by derekwallace »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: SqlQuery: Different behaviour when access DB V
« Reply #1 on: August 24, 2012, 08:52:50 am »
Quote
Does the SQL query need to change depending on the database behind the scenes?
Yes, there are lots of subtle differences between varieties of SQL. For example, "GUID" is a reserved word in MS Access SQL so you need to put it inside square brackets:
Code: [Select]
SELECT t_object.ea_guid AS [GUID]  FROM t_object
It would probably help to test your queries first in EA's custom SQL query builder (Ctrl+Alt+A, click "Builder" and open the "SQL" tab).
« Last Edit: August 24, 2012, 12:51:53 pm by KP »
The Sparx Team
[email protected]

derekwallace

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: SqlQuery: Different behaviour when access DB V
« Reply #2 on: August 24, 2012, 04:24:42 pm »
thx.
Confirmed this works for MS and MySQL
SELECT t_object.ea_guid AS [GUID]  FROM t_object

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: SqlQuery: Different behaviour when access DB V
« Reply #3 on: August 24, 2012, 04:44:42 pm »
Better yet would be to avoid keywords in (alias) names altogether.

Geert