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);
}
});
}
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();
}
}
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");
});
}
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);
});
}
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);
}
Aggregations