https://questdb.io logo
Title
l

Luc Girardin

05/16/2023, 3:04 PM
I am using the following function to test if a table is empty, but in 7.1.2 it now longer works and throw a CairoException: [-1] permission denied. Is there some kind of security that I need to configure?
fun CairoEngine.isTableEmpty(tableName: String) : Boolean {
    var empty = true
    val ctx = SqlExecutionContextImpl(this, 1)
    try {
        SqlCompiler(this).use { compiler ->
            compiler.compile(tableName, ctx).recordCursorFactory.use { factory ->
                factory.getCursor(ctx).use { cursor ->
                    if (cursor.hasNext()) {
                        empty = false
                    }
                }
            }
        }
    } catch (e: SqlException) {
    } finally {
        ctx.close()
    }
    return empty
}
i

Imre

05/16/2023, 3:16 PM
Yes, this has changed in 7.1.2. everything is rejected by default. you can get back the old functionality if you add this to your code:
ctx.with(AllowAllSecurityContex.INSTANCE, null, null)
just after you created SqlExecutionContext
l

Luc Girardin

05/16/2023, 3:38 PM
Many thanks for the prompt reply: everything works nicely 🙂