Near "*": syntax error Unable to execute statement - sql

I'm trying to execute an sqlite code that delete all values from the table 'Categories"
Here is My code:
function deleteCATs() {
var db = LocalStorage.openDatabaseSync("Cat", "1.0", "Deleting Categories File", 1000000);
db.transaction(
function(tx) {
tx.executeSql('DELETE * FROM Categories');
//tx.executeSql('DELETE FROM Categories WHERE Category ="Cat"');
}
)
}
I'm getting the following error:
"Near "*": syntax error Unable to execute statement"
Any ideas on how this can be fixed? I'm using Qt Creator 3.0.0, Qt 5.2.0 Android version

The syntax is:
DELETE FROM Categories;
(The * is not necessary.)
Or, better yet in almost any database other than SQLite:
TRUNCATE TABLE Categories;

Related

Prepared statement - with SET of run-time configuration parameters - not working

Using PG14, Hikari pool, Kotlin 1.6
I get the following error when calling, for example, a SET query:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
val input = "yes"
connection.prepareStatement("SET log_connections TO ?")
.apply {
setString(1, input)
}.use {
it.execute()
}
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 22
at app//org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2675)
at app//org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2365)
at app//org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:355)
at app//org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490)
at app//org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408)
at app//org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:167)
at app//org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:156)
at app//com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
at app//com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
I'm trying to SET run-time configuration parameters of PostgreSQL from code by creating prepared statement and set its parameters safely, but I'm getting error while running such statement. Are there any limitations for creating prepared statements that might be limiting creation of such SET statement?
You can't pass a dynamic parameter using the SET command. You need to use the set_config() function:
val input = "yes"
connection.prepareStatement("select set_config('log_connections', ?, false)")
.apply {
setString(1, input)
}.use {
it.execute()
}

kotlin exposed failed (insert is successful, but select is failure)

thanks reading this question.
I created simple kotlin project and I want to learn kotlin exposed.
I use H2 database.
I wrote code like below.
package learn.exposed.tables
import org.jetbrains.exposed.sql.Table
object AuthorTable : Table("author") {
val name = varchar("name", 30)
}
fun main() {
// this url based on http://www.h2database.com/html/features.html#execute_sql_on_connection
val url = "jdbc:h2:mem:test;INIT=runscript from 'classpath:/create.sql'\\;runscript from 'classpath:/init.sql'"
Database.connect(url, driver = "org.h2.Driver", user = "root", password = "")
transaction {
AuthorTable.insert {
it[name] = "hoge"
}
println("insert done.") // this message can show on console. I think Insert is successfull.
}
transaction {
AuthorTable.selectAll().firstOrNull()
}
}
and sql files below.
create table author (name varchar(30));
insert into author values ('author1');
When execute main(), console showing insert done.. in short, I think insert is doing well, but when execute AuthorTable.selectAll().firstOrNull(), happend Exception like below,
Exception in thread "main" org.jetbrains.exposed.exceptions.ExposedSQLException: org.h2.jdbc.JdbcSQLNonTransientException: 一般エラー: "java.lang.NullPointerException"
General error: "java.lang.NullPointerException" [50000-200]
SQL: [Failed on expanding args for SELECT: org.jetbrains.exposed.sql.Query#27406a17]
at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:62)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:135)
at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:121)
at org.jetbrains.exposed.sql.AbstractQuery.iterator(AbstractQuery.kt:65)
at kotlin.collections.CollectionsKt___CollectionsKt.firstOrNull(_Collections.kt:267)
at learn.exposed.MainKt$main$2.invoke(Main.kt:22)
at learn.exposed.MainKt$main$2.invoke(Main.kt)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:179)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.access$inTopLevelTransaction$run(ThreadLocalTransactionManager.kt:1)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$1.invoke(ThreadLocalTransactionManager.kt:205)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:213)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:204)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$transaction$1.invoke(ThreadLocalTransactionManager.kt:156)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:213)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:126)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:123)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:122)
at learn.exposed.MainKt.main(Main.kt:21)
at learn.exposed.MainKt.main(Main.kt)
can I solve this? do you know something how to solve this?
thanks.
Seems like you need at least one Primary Key(PK) or Constraint because of H2 bug.
https://github.com/h2database/h2database/issues/2191
https://github.com/JetBrains/Exposed/issues/801

Run SQL Query in Phonegap

Hello everyone i am trying to run a query as follows, but i always get "SQL ERROR: undefined"
What am i doing wrong.
db = window.openDatabase("Database", "1.0", "SQLDB", 200000);
RunQuery ("DROP TABLE IF EXISTS ARTIGOS");
function RunQuery(QueryExecute) {
db.transaction(function(transaction){
transaction.executeSql(QueryExecute,successCB,errorCB);
})
}
function errorCB(err) {
alert("SQL Error: "+err.message);
}
function successCB() {
alert("SQL OK");
}
One possibility is that the transaction.executeSql method takes a parameters array as its second argument. So to use the callbacks like you have, you may have to pass in an empty array for the parameters. e.g.:
transaction.executeSql(QueryExecute, [], successCB, errorCB);
Referenced from the Cordova docs here:
https://cordova.apache.org/docs/en/latest/cordova/storage/storage.html

Ignite Query Exception

Im getting the following error:
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "SELECT
""standard_item_cache"".""STANDARDITEM""._KEY,
""standard_item_cache"".""STANDARDITEM""._VAL FROM
""standard_item_cache"".""STANDARDITEM"" WHERE ITEMID[*] == ? "; SQL statement:
SELECT "standard_item_cache"."STANDARDITEM"._KEY,
"standard_item_cache"."STANDARDITEM"._VAL FROM
"standard_item_cache"."STANDARDITEM" WHERE itemId == ? [42000-196]
When I try to perform a simple query:
String itemId = params.get(Params.PARAM_ITEM_ID);
SqlQuery<String, StandardItem> sql = new SqlQuery<>(StandardItem.class, "itemid == ?");
try (QueryCursor<Cache.Entry<String, StandardItem>> cursor = standardItemIgniteCache.query(sql.setArgs(itemId))) {
logger.info("publish standard items from cache");
for (Cache.Entry<String, StandardItem> entry : cursor) {
logger.info("publish standard item: " + entry.getValue().toString());
}
logger.info("publishing standard items from cache done");
cursor.close();
}
Where is the mistake? Im doint it exactly like it is described in the apache ignite examples: https://apacheignite.readme.io/v1.0/docs/cache-queries
The mistake is in this tiny string: itemid == ?.
You used == instead of =. SQL equality operator is a single =.

Xquery ERROR err:XPDY0002: undefined value for variable $skill

I am trying to use xquery for a project and I cannot see why this query is not working. It gives me the following error:
err:XPDY0002: undefined value for variable $skill
I am new to xquery and I am using EXIST DB as a database and I have tried using base x db and this works there perfectly. Is there anything i am missing in existdb? Any help would be appeciated.
for $endorsement in doc('/db/users.xml')/LOUser/Endorsements
for $endorsed_skill in $endorsement/Skills
let $skill := $endorsed_skill/text()
for $user in doc('/db/users.xml')/LOUser/User[#URL = $endorsement/URL2/text()]
let $Name := $user/Name/text()
where not($user/Skills/text() = $skill)/* I am getting the error here*/
group by
$Name, $skill
return {$Name}