Search in sources :

Example 71 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class ResultTempTable method find.

private Cursor find(Row row) {
    if (index == null) {
        // for the case "in(select ...)", the query might
        // use an optimization and not create the index
        // up front
        createIndex();
    }
    Cursor cursor = index.find(session, row, row);
    while (cursor.next()) {
        SearchRow found = cursor.getSearchRow();
        boolean ok = true;
        Database db = session.getDatabase();
        for (int i = 0; i < row.getColumnCount(); i++) {
            if (!db.areEqual(row.getValue(i), found.getValue(i))) {
                ok = false;
                break;
            }
        }
        if (ok) {
            return cursor;
        }
    }
    return null;
}
Also used : Database(org.h2.engine.Database) Cursor(org.h2.index.Cursor)

Example 72 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class UpdatableRow method deleteRow.

/**
 * Delete the given row in the database.
 *
 * @param current the row
 * @throws SQLException if this row has already been deleted
 */
public void deleteRow(Value[] current) throws SQLException {
    StatementBuilder buff = new StatementBuilder("DELETE FROM ");
    appendTableName(buff);
    appendKeyCondition(buff);
    PreparedStatement prep = conn.prepareStatement(buff.toString());
    setKey(prep, 1, current);
    int count = prep.executeUpdate();
    if (count != 1) {
        // the row has already been deleted
        throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
    }
}
Also used : StatementBuilder(org.h2.util.StatementBuilder) PreparedStatement(java.sql.PreparedStatement)

Example 73 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class UpdatableRow method readRow.

/**
 * Re-reads a row from the database and updates the values in the array.
 *
 * @param row the values that contain the key
 * @return the row
 */
public Value[] readRow(Value[] row) throws SQLException {
    StatementBuilder buff = new StatementBuilder("SELECT ");
    appendColumnList(buff, false);
    buff.append(" FROM ");
    appendTableName(buff);
    appendKeyCondition(buff);
    PreparedStatement prep = conn.prepareStatement(buff.toString());
    setKey(prep, 1, row);
    ResultSet rs = prep.executeQuery();
    if (!rs.next()) {
        throw DbException.get(ErrorCode.NO_DATA_AVAILABLE);
    }
    Value[] newRow = new Value[columnCount];
    for (int i = 0; i < columnCount; i++) {
        int type = result.getColumnType(i);
        newRow[i] = DataType.readValue(conn.getSession(), rs, i + 1, type);
    }
    return newRow;
}
Also used : StatementBuilder(org.h2.util.StatementBuilder) ResultSet(java.sql.ResultSet) Value(org.h2.value.Value) PreparedStatement(java.sql.PreparedStatement)

Example 74 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class WebServer method readTranslations.

/**
 * Read the translation for this language and save them in the 'text'
 * property of this session.
 *
 * @param session the session
 * @param language the language
 */
void readTranslations(WebSession session, String language) {
    Properties text = new Properties();
    try {
        trace("translation: " + language);
        byte[] trans = getFile("_text_" + language + ".prop");
        trace("  " + new String(trans));
        text = SortedProperties.fromLines(new String(trans, StandardCharsets.UTF_8));
        // remove starting # (if not translated yet)
        for (Entry<Object, Object> entry : text.entrySet()) {
            String value = (String) entry.getValue();
            if (value.startsWith("#")) {
                entry.setValue(value.substring(1));
            }
        }
    } catch (IOException e) {
        DbException.traceThrowable(e);
    }
    session.put("text", new HashMap<>(text));
}
Also used : IOException(java.io.IOException) SortedProperties(org.h2.util.SortedProperties) SysProperties(org.h2.engine.SysProperties) Properties(java.util.Properties)

Example 75 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class WebServer method init.

@Override
public void init(String... args) {
    // set the serverPropertiesDir, because it's used in loadProperties()
    for (int i = 0; args != null && i < args.length; i++) {
        if ("-properties".equals(args[i])) {
            serverPropertiesDir = args[++i];
        }
    }
    Properties prop = loadProperties();
    port = SortedProperties.getIntProperty(prop, "webPort", Constants.DEFAULT_HTTP_PORT);
    ssl = SortedProperties.getBooleanProperty(prop, "webSSL", false);
    allowOthers = SortedProperties.getBooleanProperty(prop, "webAllowOthers", false);
    commandHistoryString = prop.getProperty(COMMAND_HISTORY);
    for (int i = 0; args != null && i < args.length; i++) {
        String a = args[i];
        if (Tool.isOption(a, "-webPort")) {
            port = Integer.decode(args[++i]);
        } else if (Tool.isOption(a, "-webSSL")) {
            ssl = true;
        } else if (Tool.isOption(a, "-webAllowOthers")) {
            allowOthers = true;
        } else if (Tool.isOption(a, "-webDaemon")) {
            isDaemon = true;
        } else if (Tool.isOption(a, "-baseDir")) {
            String baseDir = args[++i];
            SysProperties.setBaseDir(baseDir);
        } else if (Tool.isOption(a, "-ifExists")) {
            ifExists = true;
        } else if (Tool.isOption(a, "-properties")) {
            // already set
            i++;
        } else if (Tool.isOption(a, "-trace")) {
            trace = true;
        }
    }
    // }
    for (String[] lang : LANGUAGES) {
        languages.add(lang[0]);
    }
    updateURL();
}
Also used : SortedProperties(org.h2.util.SortedProperties) SysProperties(org.h2.engine.SysProperties) Properties(java.util.Properties)

Aggregations

SQLException (java.sql.SQLException)63 Connection (java.sql.Connection)59 DbException (org.h2.message.DbException)56 PreparedStatement (java.sql.PreparedStatement)54 ResultSet (java.sql.ResultSet)47 Statement (java.sql.Statement)44 Value (org.h2.value.Value)40 IOException (java.io.IOException)39 ByteArrayInputStream (java.io.ByteArrayInputStream)30 InputStream (java.io.InputStream)29 Column (org.h2.table.Column)24 ArrayList (java.util.ArrayList)23 SimpleResultSet (org.h2.tools.SimpleResultSet)23 Random (java.util.Random)19 Expression (org.h2.expression.Expression)18 JdbcConnection (org.h2.jdbc.JdbcConnection)18 Index (org.h2.index.Index)16 ValueString (org.h2.value.ValueString)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)15