Skip to content

Commit

Permalink
add preliminary support for Firebird SQL dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
cyganiak committed Nov 3, 2010
1 parent 08da8d1 commit 1b9d579
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/de/fuberlin/wiwiss/d2rq/sql/BeanCounter.java
Expand Up @@ -4,8 +4,10 @@
* A class for capturing performance information.
* We grant read/write access to instance variables.
*
* TODO: Remove?
*
* @author jgarbers
* @version $Id: BeanCounter.java,v 1.1 2006/09/11 23:22:25 cyganiak Exp $
* @version $Id: BeanCounter.java,v 1.2 2010/11/03 18:48:17 cyganiak Exp $
*/
public class BeanCounter implements Cloneable {

Expand Down
11 changes: 8 additions & 3 deletions src/de/fuberlin/wiwiss/d2rq/sql/ConnectedDB.java
Expand Up @@ -27,7 +27,7 @@
* TODO Move all engine-specific code from ConnectedDB to this interface and its implementing classes
*
* @author Richard Cyganiak (richard@cyganiak.de)
* @version $Id: ConnectedDB.java,v 1.36 2010/01/26 16:15:46 fatorange Exp $
* @version $Id: ConnectedDB.java,v 1.37 2010/11/03 18:48:17 cyganiak Exp $
*/
public class ConnectedDB {
private static final Log log = LogFactory.getLog(ConnectedDB.class);
Expand All @@ -38,6 +38,8 @@ public class ConnectedDB {
public static final String MSSQL = "Microsoft SQL Server";
public static final String MSAccess = "Microsoft Access";
public static final String Other = "Other";
public static final String Firebird = "Firebird";

public static final int TEXT_COLUMN = 1;
public static final int NUMERIC_COLUMN = 2;
public static final int DATE_COLUMN = 3;
Expand Down Expand Up @@ -315,7 +317,10 @@ private void ensureDatabaseTypeInitialized() {
this.syntax = new MySQLSyntax();
} else if (productName.indexOf("postgresql") >= 0) {
this.dbType = ConnectedDB.PostgreSQL;
this.syntax = new SQL92Syntax();
this.syntax = new SQL92Syntax(true);
} else if (productName.indexOf("firebird") >= 0) {
this.dbType = ConnectedDB.Firebird;
this.syntax = new SQL92Syntax(false);
} else if (productName.indexOf("oracle") >= 0) {
this.dbType = ConnectedDB.Oracle;
this.syntax = new OracleSyntax();
Expand All @@ -327,7 +332,7 @@ private void ensureDatabaseTypeInitialized() {
this.syntax = new MSSQLSyntax();
} else {
this.dbType = ConnectedDB.Other;
this.syntax = new SQL92Syntax();
this.syntax = new SQL92Syntax(true);
}
} catch (SQLException ex) {
throw new D2RQException("Database exception", ex);
Expand Down
6 changes: 5 additions & 1 deletion src/de/fuberlin/wiwiss/d2rq/sql/MSSQLSyntax.java
Expand Up @@ -7,10 +7,14 @@
* and MS Access.
*
* @author Richard Cyganiak (richard@cyganiak.de)
* @version $Id: MSSQLSyntax.java,v 1.1 2009/09/29 19:56:53 cyganiak Exp $
* @version $Id: MSSQLSyntax.java,v 1.2 2010/11/03 18:48:17 cyganiak Exp $
*/
public class MSSQLSyntax extends SQL92Syntax {

public MSSQLSyntax() {
super(true);
}

public String getRowNumLimitAsSelectModifier(int limit) {
if (limit == Database.NO_LIMIT) return "";
return "TOP " + limit;
Expand Down
6 changes: 5 additions & 1 deletion src/de/fuberlin/wiwiss/d2rq/sql/MySQLSyntax.java
Expand Up @@ -7,10 +7,14 @@
* This syntax class implements MySQL-compatible SQL syntax.
*
* @author Richard Cyganiak (richard@cyganiak.de)
* @version $Id: MySQLSyntax.java,v 1.1 2009/09/29 19:56:53 cyganiak Exp $
* @version $Id: MySQLSyntax.java,v 1.2 2010/11/03 18:48:17 cyganiak Exp $
*/
public class MySQLSyntax extends SQL92Syntax {

public MySQLSyntax() {
super(true);
}

public String getConcatenationExpression(String[] sqlFragments) {
StringBuffer result = new StringBuffer("CONCAT(");
for (int i = 0; i < sqlFragments.length; i++) {
Expand Down
8 changes: 3 additions & 5 deletions src/de/fuberlin/wiwiss/d2rq/sql/OracleSyntax.java
@@ -1,6 +1,5 @@
package de.fuberlin.wiwiss.d2rq.sql;

import de.fuberlin.wiwiss.d2rq.algebra.RelationName;
import de.fuberlin.wiwiss.d2rq.expr.Expression;
import de.fuberlin.wiwiss.d2rq.expr.SQLExpression;
import de.fuberlin.wiwiss.d2rq.map.Database;
Expand All @@ -9,13 +8,12 @@
* This syntax class implements MySQL-compatible SQL syntax.
*
* @author Richard Cyganiak (richard@cyganiak.de)
* @version $Id: OracleSyntax.java,v 1.1 2009/09/29 19:56:53 cyganiak Exp $
* @version $Id: OracleSyntax.java,v 1.2 2010/11/03 18:48:17 cyganiak Exp $
*/
public class OracleSyntax extends SQL92Syntax {

public String getRelationNameAliasExpression(RelationName relationName,
RelationName aliasName) {
return quoteRelationName(relationName) + " " + quoteRelationName(aliasName);
public OracleSyntax() {
super(false);
}

public Expression getRowNumLimitAsExpression(int limit) {
Expand Down
16 changes: 13 additions & 3 deletions src/de/fuberlin/wiwiss/d2rq/sql/SQL92Syntax.java
Expand Up @@ -13,10 +13,20 @@
* can override individual methods to implement different syntax.
*
* @author Richard Cyganiak (richard@cyganiak.de)
* @version $Id: SQL92Syntax.java,v 1.1 2009/09/29 19:56:53 cyganiak Exp $
* @version $Id: SQL92Syntax.java,v 1.2 2010/11/03 18:48:17 cyganiak Exp $
*/
public class SQL92Syntax implements SQLSyntax {

private boolean useAS;

/**
* Initializes a new instance.
*
* @param useAS Use "Table AS Alias" or "Table Alias" in FROM clauses? In standard SQL, either is fine.
*/
public SQL92Syntax(boolean useAS) {
this.useAS = useAS;
}

public String getConcatenationExpression(String[] sqlFragments) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < sqlFragments.length; i++) {
Expand All @@ -30,7 +40,7 @@ public String getConcatenationExpression(String[] sqlFragments) {

public String getRelationNameAliasExpression(RelationName relationName,
RelationName aliasName) {
return quoteRelationName(relationName) + " AS " + quoteRelationName(aliasName);
return quoteRelationName(relationName) + (useAS ? " AS " : " ") + quoteRelationName(aliasName);
}

public String quoteAttribute(Attribute attribute) {
Expand Down

0 comments on commit 1b9d579

Please sign in to comment.