Search in sources :

Example 6 with SQLText

use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.

the class SybaseAdapter method getUpdateTableStatement.

/**
 * Method to return the SQLText for an UPDATE TABLE statement.
 * Returns the SQLText for <code>UPDATE T1 SET x1 = val1, x2 = val2 FROM MYTBL T1</code>.
 * Override if the datastore doesn't support that standard syntax.
 * @param tbl The primary table
 * @param setSQL The SQLText for the SET component
 * @return SQLText for the update statement
 */
public SQLText getUpdateTableStatement(SQLTable tbl, SQLText setSQL) {
    // "UPDATE T1"
    SQLText sql = new SQLText("UPDATE ").append(tbl.getAlias().toString());
    // " SET x1 = val1, x2 = val2"
    sql.append(" ").append(setSQL);
    // " FROM MYTBL T1"
    sql.append(" FROM ").append(tbl.toString());
    return sql;
}
Also used : SQLText(org.datanucleus.store.rdbms.sql.SQLText)

Example 7 with SQLText

use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.

the class BaseDatastoreAdapter method getUpdateTableStatement.

/**
 * Method to return the SQLText for an UPDATE TABLE statement.
 * Returns the SQLText for <code>UPDATE tbl t1 SET x1 = val1, x2 = val2</code>.
 * Override if the datastore doesn't support that standard syntax.
 * @param tbl The primary table
 * @param setSQL The SQLText for the SET component
 * @return SQLText for the update statement
 */
public SQLText getUpdateTableStatement(SQLTable tbl, SQLText setSQL) {
    SQLText sql = new SQLText("UPDATE ");
    // "MYTBL T1"
    sql.append(tbl.toString());
    sql.append(" ").append(setSQL);
    return sql;
}
Also used : SQLText(org.datanucleus.store.rdbms.sql.SQLText)

Example 8 with SQLText

use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.

the class StringTrim3Method method getExpression.

/* (non-Javadoc)
     * @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
     */
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args) {
    if (args != null && args.size() > 1) {
        throw new NucleusException("TRIM has incorrect number of args");
    }
    // {stringExpr}.trim(trimChar)
    SQLExpression trimCharExpr = null;
    if (args != null && args.size() > 0) {
        trimCharExpr = args.get(0);
    }
    List trimArgs = new ArrayList();
    if (trimCharExpr == null) {
        trimArgs.add(expr);
    } else {
        StringExpression argExpr = new StringExpression(stmt, expr.getJavaTypeMapping(), "NULL", null);
        SQLText sql = argExpr.toSQLText();
        sql.clearStatement();
        sql.append(getTrimSpecKeyword() + " ");
        sql.append(trimCharExpr);
        sql.append(" FROM ");
        sql.append(expr);
        trimArgs.add(argExpr);
    }
    StringExpression trimExpr = new StringExpression(stmt, expr.getJavaTypeMapping(), "TRIM", trimArgs);
    return trimExpr;
}
Also used : SQLExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression) StringExpression(org.datanucleus.store.rdbms.sql.expression.StringExpression) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) NucleusException(org.datanucleus.exceptions.NucleusException) SQLText(org.datanucleus.store.rdbms.sql.SQLText)

Example 9 with SQLText

use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.

the class SQLiteAdapter method getUpdateTableStatement.

/**
 * Method to return the SQLText for an UPDATE TABLE statement.
 * Returns the SQLText for <code>UPDATE SCH1.TBL1 SET x1 = val1, x2 = val2</code> since SQLite doesn't allow any aliases in UPDATEs.
 * @param tbl The primary table
 * @param setSQL The SQLText for the SET component
 * @return SQLText for the update statement
 */
public SQLText getUpdateTableStatement(SQLTable tbl, SQLText setSQL) {
    // "UPDATE SCH1.TBL1"
    SQLText sql = new SQLText("UPDATE ").append(tbl.getTable().toString());
    // " SET x1 = val1, x2 = val2"
    sql.append(" ").append(setSQL);
    return sql;
}
Also used : SQLText(org.datanucleus.store.rdbms.sql.SQLText)

Aggregations

SQLText (org.datanucleus.store.rdbms.sql.SQLText)9 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BaseDatastoreAdapter (org.datanucleus.store.rdbms.adapter.BaseDatastoreAdapter)2 BooleanExpression (org.datanucleus.store.rdbms.sql.expression.BooleanExpression)2 CharacterLiteral (org.datanucleus.store.rdbms.sql.expression.CharacterLiteral)2 SQLExpression (org.datanucleus.store.rdbms.sql.expression.SQLExpression)2 SQLExpressionFactory (org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory)2 StringExpression (org.datanucleus.store.rdbms.sql.expression.StringExpression)2 NucleusException (org.datanucleus.exceptions.NucleusException)1 JavaTypeMapping (org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping)1