Search in sources :

Example 1 with InsertMethod

use of io.questdb.cairo.sql.InsertMethod in project questdb by bluestreak01.

the class TelemetryTest method testTelemetryConfigUpgrade.

@Test
public void testTelemetryConfigUpgrade() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
            compiler.compile("CREATE TABLE " + TelemetryJob.configTableName + " (id long256, enabled boolean)", sqlExecutionContext);
            InsertStatement ist = compiler.compile("INSERT INTO " + TelemetryJob.configTableName + " values(CAST('0x01' AS LONG256), true)", sqlExecutionContext).getInsertStatement();
            InsertMethod im = ist.createMethod(sqlExecutionContext);
            im.execute();
            im.commit();
            im.close();
            ist.close();
            TelemetryJob telemetryJob = new TelemetryJob(engine, null);
            String expectedSql = "column	type	indexed	indexBlockCapacity	symbolCached	symbolCapacity	designated\n" + "id	LONG256	false	0	false	0	false\n" + "enabled	BOOLEAN	false	0	false	0	false\n" + "version	SYMBOL	false	256	true	128	false\n" + "os	SYMBOL	false	256	true	128	false\n" + "package	SYMBOL	false	256	true	128	false\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SHOW COLUMNS FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "id\tversion\n" + "0x01\t\n" + "0x01\tUnknown Version\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT id, version FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) InsertMethod(io.questdb.cairo.sql.InsertMethod) CairoEngine(io.questdb.cairo.CairoEngine) InsertStatement(io.questdb.cairo.sql.InsertStatement) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 2 with InsertMethod

use of io.questdb.cairo.sql.InsertMethod in project questdb by bluestreak01.

the class SimulatedDeleteTest method execInsert.

private static void execInsert(InsertStatement statement) throws SqlException {
    try (InsertMethod m = statement.createMethod(sqlExecutionContext)) {
        m.execute();
        m.commit();
    }
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod)

Example 3 with InsertMethod

use of io.questdb.cairo.sql.InsertMethod in project questdb by bluestreak01.

the class SecurityTest method testAlterTableDeniedOnNoWriteAccess.

@Test
public void testAlterTableDeniedOnNoWriteAccess() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
        CompiledQuery cq = compiler.compile("insert into balances values (1, 'EUR', 140.6)", sqlExecutionContext);
        InsertStatement insertStatement = cq.getInsertStatement();
        try (InsertMethod method = insertStatement.createMethod(sqlExecutionContext)) {
            method.execute();
            method.commit();
        }
        assertQuery("cust_id\tccy\tbalance\n1\tEUR\t140.6\n", "select * from balances", null, true, true);
        try {
            compiler.compile("alter table balances add column newcol int", readOnlyExecutionContext);
            Assert.fail();
        } catch (Exception ex) {
            Assert.assertTrue(ex.toString().contains("permission denied"));
        }
        assertQueryPlain("cust_id\tccy\tbalance\n1\tEUR\t140.6\n", "select * from balances");
    });
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) InsertStatement(io.questdb.cairo.sql.InsertStatement) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test)

Example 4 with InsertMethod

use of io.questdb.cairo.sql.InsertMethod in project questdb by bluestreak01.

the class SecurityTest method testInsertDeniedOnNoWriteAccess.

@Test
public void testInsertDeniedOnNoWriteAccess() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table balances(cust_id int, ccy symbol, balance double)", sqlExecutionContext);
        assertQuery("count\n0\n", "select count() from balances", null, false, true);
        CompiledQuery cq = compiler.compile("insert into balances values (1, 'EUR', 140.6)", sqlExecutionContext);
        InsertStatement insertStatement = cq.getInsertStatement();
        try (InsertMethod method = insertStatement.createMethod(sqlExecutionContext)) {
            method.execute();
            method.commit();
        }
        assertQuery("count\n1\n", "select count() from balances", null, false, true);
        try {
            cq = compiler.compile("insert into balances values (2, 'ZAR', 140.6)", readOnlyExecutionContext);
            insertStatement = cq.getInsertStatement();
            try (InsertMethod method = insertStatement.createMethod(readOnlyExecutionContext)) {
                method.execute();
                method.commit();
            }
            Assert.fail();
        } catch (Exception ex) {
            Assert.assertTrue(ex.toString().contains("permission denied"));
        }
        assertQuery("count\n1\n", "select count() from balances", null, false, true);
    });
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) InsertStatement(io.questdb.cairo.sql.InsertStatement) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test)

Example 5 with InsertMethod

use of io.questdb.cairo.sql.InsertMethod in project questdb by bluestreak01.

the class JsonQueryProcessor method executeInsert.

private void executeInsert(JsonQueryProcessorState state, CompiledQuery cc, CharSequence keepAliveHeader) throws PeerDisconnectedException, PeerIsSlowToReadException, SqlException {
    final InsertStatement insertStatement = cc.getInsertStatement();
    try (InsertMethod insertMethod = insertStatement.createMethod(sqlExecutionContext)) {
        insertMethod.execute();
        insertMethod.commit();
    }
    sendConfirmation(state, cc, keepAliveHeader);
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) InsertStatement(io.questdb.cairo.sql.InsertStatement)

Aggregations

InsertMethod (io.questdb.cairo.sql.InsertMethod)6 InsertStatement (io.questdb.cairo.sql.InsertStatement)5 Test (org.junit.Test)3 CairoException (io.questdb.cairo.CairoException)2 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)1 CairoEngine (io.questdb.cairo.CairoEngine)1 CompiledQuery (io.questdb.griffin.CompiledQuery)1 SqlCompiler (io.questdb.griffin.SqlCompiler)1 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)1 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)1