Sql error or missing database near syntax error

I'm trying to get requery + SQLite to work under Kotlin. I don't see any apparent issues with my models or the database setup. Stacktrace: INFO: beforeExecuteUpdate org.sqlite.jdbc4.JDBC4St...

I’m trying to get requery + SQLite to work under Kotlin.

I don’t see any apparent issues with my models or the database setup.

Stacktrace:

INFO: beforeExecuteUpdate org.sqlite.jdbc4.JDBC4Statement@29176cc1 sql:
drop table if exists QueryItem 
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener afterExecuteUpdate
INFO: afterExecuteUpdate 0
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener beforeExecuteUpdate
INFO: beforeExecuteUpdate org.sqlite.jdbc4.JDBC4Statement@29176cc1 sql:
drop table if exists Beer 
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener afterExecuteUpdate
INFO: afterExecuteUpdate 0
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener beforeExecuteUpdate
INFO: beforeExecuteUpdate org.sqlite.jdbc4.JDBC4Statement@29176cc1 sql:
drop table if exists Details 
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener afterExecuteUpdate
INFO: afterExecuteUpdate 0
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener beforeExecuteUpdate
INFO: beforeExecuteUpdate org.sqlite.jdbc4.JDBC4Statement@29176cc1 sql:
create table Details (id integer primary key autoincrement not null, description varchar(255), details varchar(255), productID varchar(255), stock integer not null)
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener afterExecuteUpdate
INFO: afterExecuteUpdate 0
Sep 06, 2018 1:49:41 PM io.requery.sql.LoggingListener beforeExecuteUpdate
INFO: beforeExecuteUpdate org.sqlite.jdbc4.JDBC4Statement@29176cc1 sql:
create table Beer (id integer autoincrement not null, parseDate integer not null, details integer, image varchar(255), name varchar(255), price float not null, url varchar(255), foreign key (details) references Details (id) on delete cascade, primary key (id, parseDate))
Exception in thread "main" io.requery.sql.TableModificationException: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (near "autoincrement": syntax error)
	at io.requery.sql.SchemaModifier.createTables(SchemaModifier.java:162)
	at io.requery.sql.SchemaModifier.createTables(SchemaModifier.java:128)
	at MainKt.main(main.kt:18)
Caused by: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (near "autoincrement": syntax error)
	at org.sqlite.core.DB.newSQLException(DB.java:909)
	at org.sqlite.core.DB.newSQLException(DB.java:921)
	at org.sqlite.core.DB.throwex(DB.java:886)
	at org.sqlite.core.NativeDB.prepare_utf8(Native Method)
	at org.sqlite.core.NativeDB.prepare(NativeDB.java:127)
	at org.sqlite.core.DB.prepare(DB.java:227)
	at org.sqlite.jdbc3.JDBC3Statement.execute(JDBC3Statement.java:60)
	at io.requery.sql.SchemaModifier.createTables(SchemaModifier.java:153)
	... 2 more

DB Setup:

    val datasource = SQLiteDataSource()
    datasource.url = "jdbc:sqlite:beers.db"

    val config = ConfigurationBuilder(datasource, Models.DEFAULT)
            .useDefaultLogging()
            .build()

    val tables = SchemaModifier(config)
    tables.createTables(TableCreationMode.DROP_CREATE)

    val dataStore = KotlinEntityDataStore<Persistable>(config)
}

Models:

interface Beer : Persistable {

    @get:Key
    @get:Generated
    var id: Int

    @get:Key
    var parseDate: Long

    var price: Float
    var name: String
    var url: String
    var image: String

    @get:OneToOne(mappedBy = "beer")
    @get:ForeignKey
    var details: Details

    @get:OneToMany(mappedBy = "beer")
    var queryResults: Set<QueryItem>
}

@Entity
interface Details : Persistable {
    @get:Key
    @get:Generated
    var id: Int

    @get:OneToOne(mappedBy = "details")
    var beer: Beer

    var productID: String
    var stock: Int
    var description: String
    var details: MutableMap<String, String>
}

@Entity
interface QueryItem : Persistable {

    @get:Key
    @get:Generated
    var id: Int

    @get:Key
    var queryDate: Long

    @get:ManyToOne
    var beer: Beer

    var name: String
    var style: String
    var styleScore: Float
    var overallScore: Float
    var averageRating: Float
    var ratingCount: Int
    var imageUrl: String
}

Is there anything obviously wrong with this code? If so please point me in the right direction.

  • Remove From My Forums
  • Question

  •     

                SQLiteCommand command = new SQLiteCommand(connection);
                command.CommandText = "UPDATE glasba SET Naslov ='" + textBox1.Text+"', Izvajalec = '"+textBox2.Text+"', Zanr ='"+textBox3.Text+"', Ocena ='"+textBox4.Text+"') WHERE (Naslov = '" + imes + "') AND (Izvajalec = '" + imea + "') ";
                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
                this.Hide();

    System.Data.SQLite.SQLiteException
      HResult=0x80004005
      Message=SQL logic error or missing database
    near «=»: syntax error

    I dont know what to do, this error getting up even though i tried adding parameters and so on…

Answers

  • Hi

    Thank you for posting here.

    According to your description, you want to solve the error that ’ System.Data.SQLite.SQLiteException’.

    You could try the following code.

                SQLiteConnection connection = new SQLiteConnection(@"Data Source = MyDatabase.sqlite");
                connection.Open();
                string sql = String.Format("UPDATE glasba SET naslov ='{0}', izvajalec='{1}',zanr='{2}',ocena='{3}' ,review='{4}' WHERE naslov = 'test1' and izvajalec='test2'",textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text);
                SQLiteCommand command = new SQLiteCommand(sql,connection);
                command.ExecuteNonQuery();
                connection.Close();
    
    

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
    MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by

      Tuesday, March 26, 2019 5:14 PM

    • Unproposed as answer by
      Cherkaoui.Mouad
      Tuesday, March 26, 2019 5:15 PM
    • Marked as answer by
      Twinkiiee
      Wednesday, April 3, 2019 2:43 PM

I’m trying to create a table that will contain the user’s messages. The current Messages.java file is like this:

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.PrimaryKey;

@Entity(tableName = "MESSAGES")
public class Messages {

    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "MessageID")
    public int message_id;

    @ForeignKey(entity = User.class, parentColumns = "ID_card", childColumns = "MessageSender", onDelete = ForeignKey.CASCADE)
    @ColumnInfo(name = "MessageSender")
    public int message_sender;

    @ForeignKey(entity = User.class, parentColumns = "ID_card", childColumns = "MessageReceiver", onDelete = ForeignKey.CASCADE)
    @ColumnInfo(name = "MessageReceiver")
    public int message_receiver;

    @ForeignKey(entity = Conversation.class, parentColumns = "ConvoID", childColumns = "ConvoID", onDelete = ForeignKey.CASCADE)
    @ColumnInfo(name = "ConvoID")
    public int convo_id;

    @ColumnInfo(name = "DateReceived", defaultValue = "julianday('now')")
    public double date_received;

    @ColumnInfo(name = "Message")
    public String message;
}

and the MessagesDao.java file is like this:

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;

import java.util.List;

@Dao
public interface MessagesDao {
    @Query("SELECT MessageID, MessageSender, MessageReceiver, Message, DATE(DateReceived) AS Date, TIME(DateReceived) AS Time FROM Messages WHERE ConvoID = :ConvoID")
    LiveData<List<Messages>> getAllConvoMessagesById(int ConvoID);

    @Query("SELECT MessageSender, MessageReceiver, Message, DATE(DateReceived) AS Date, TIME(DateReceived) AS Time FROM Messages WHERE MessageID = :MessageID LIMIT 1")
    LiveData<List<Messages>> getMessageById(int MessageID);

    @Query("SELECT MessageSender, MessageReceiver, Message, TIME(DateReceived) AS Time FROM Messages WHERE DATE(DateReceived) = :DateReceived")
    LiveData<List<Messages>> getMessagesByDate(double DateReceived);

    @Insert
    void insert(Messages messages);

    @Delete
    void delete(Messages messages);

}

Since I’m getting error: [SQLITE_ERROR] SQL error or missing database (near '(': syntax error) in Messages.java, any SQLite query in MessagesDao.java is not being recognized, (Messages.class is included in AppDatabase.java).

I don’t understand why this exists because «Messages» is not a Keyword in SQLite and all the other tables that I have look similar to this, but only this specific table is the one that’s getting this error.

Before I forget, If you see any other area you think I can improve my code (even if it’s not related to the question) feel free to let me know.

Thread Status:

Not open for further replies.
  1. I’m able to reproduce the error (SQLException) by doing:

    database.query("CREATE TABLE PLAYERDATA (NAME TEXT PRIMARY KEY NOT NULL, POINTS INT DEFAULT 0 NOT NULL);");
    database.query("INSERT OR IGNORE INTO PLAYERDATA (NAME, POINTS) VALUES ('a', 1)");
    database.query("INSERT OR IGNORE INTO PLAYERDATA (NAME, POINTS) VALUES ('b', 2), ('c', 3);");

    upon debugging I noticed that line 1 executed properly, line 2 executed properly, but line 3 doesn’t.

    error message:

    [18:29:36 WARN]: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ",": syntax error)
    [18:29:36 WARN]:  at org.sqlite.DB.newSQLException(DB.java:383)
    [18:29:36 WARN]:  at org.sqlite.DB.newSQLException(DB.java:387)
    [18:29:36 WARN]:  at org.sqlite.DB.throwex(DB.java:374)
    [18:29:36 WARN]:  at org.sqlite.NativeDB.prepare(Native Method)
    [18:29:36 WARN]:  at org.sqlite.DB.prepare(DB.java:123)
    [18:29:36 WARN]:  at org.sqlite.Stmt.execute(Stmt.java:113)
    [18:29:36 WARN]:  at lib.PatPeter.SQLibrary.Database.query(Database.java:242)
    [18:29:36 WARN]:  at ye.reproduce.output.MainClass.onEnable(MainClass.java:33)
    [18:29:36 WARN]:  at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    [18:29:36 WARN]:  at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    [18:29:36 WARN]:  at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [18:29:36 WARN]:  at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357)
    [18:29:36 WARN]:  at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317)
    [18:29:36 WARN]:  at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741)
    [18:29:36 WARN]:  at org.bukkit.Bukkit.reload(Bukkit.java:535)
    [18:29:36 WARN]:  at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25)
    [18:29:36 WARN]:  at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [18:29:36 WARN]:  at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641)
    [18:29:36 WARN]:  at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627)
    [18:29:36 WARN]:  at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412)
    [18:29:36 WARN]:  at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375)
    [18:29:36 WARN]:  at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654)
    [18:29:36 WARN]:  at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557)
    [18:29:36 WARN]:  at java.lang.Thread.run(Unknown Source)

    here’s the minimal code to reproduce the output:

    main class:

    package ye.reproduce.output;
    
    import lib.PatPeter.SQLibrary.Database;
    import lib.PatPeter.SQLibrary.SQLite;
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.sql.SQLException;
    import java.util.logging.Level;
    
    public class MainClass extends JavaPlugin {
      private Database sql = new SQLite(getServer().getLogger(),
      "[error_reproducer]",
      this.getDataFolder().getAbsolutePath(),
      "er",
      ".db");
    
      @Override
      public void onEnable() {
      if (!Bukkit.getPluginManager().isPluginEnabled("SQLibrary")) {
        Bukkit.getLogger().log(
        Level.SEVERE,
        "Plugin was unable to start | SQLibrary is not installed"
        );
    
        this.setEnabled(false);
        return;
      }
    
      try {
        if (sql.open()) {
        sql.query("CREATE TABLE PLAYERDATA (NAME TEXT PRIMARY KEY NOT NULL, POINTS INT DEFAULT 0 NOT NULL);");
        sql.query("INSERT OR IGNORE INTO PLAYERDATA (NAME, POINTS) VALUES ('a', 1), ('b', 2);");
        }
      } catch (SQLException e) {
        e.printStackTrace();
        }
      }
    
      @Override
      public void onDisable() {
    
      }
    }

    here’s the (raw) snippet in case you’re experiencing whitespacing issue: http://pastebin.com/raw.php?i=Tytb1LC5

    Thanks for your help!

    Last edited: Sep 29, 2015

  2. I recomend you use this syntax checker:
    http://www.piliapp.com/mysql-syntax-check/
    that can pinpoint the syntax error.
    I am not an SQL guru so i dont think i can help further than telling you that line 33 is the one with the issue.

    Good luck.

  3. Might be that your version of sqlite is not supporting inserting multiple rows with your syntax. See here: http://stackoverflow.com/questions/…multiple-rows-at-a-time-in-an-sqlite-database

    You can find out the version of your sqlite database with «select sqlite_version();»

  4. I’m using SQLite, removing «OR IGNORE» gives me no errorit gives me NPE. What I do remember though is I CAN insert multiple values into the table before. I’ve tried creating another plain plugin without all the stuff except the query one, but it didn’t work, which is really confusing.

    okay so before I created this thread I tried the UNION method, it didn’t work. But now it does. weird.

    (I still want to do the ‘,’ method, if no solution is found, then I will mark this as [Solved])

    Last edited: Sep 29, 2015

  5. That isn’t SQL. I recommend you read up on SQL syntax before you try to write SQL.

  6. from my understanding you’re saying that the syntax is incorrect. In SQLite you can do that, see: https://www.sqlite.org/lang_insert.html

    The following is when the above query is executed on sqlite3

    sqlite> CREATE TABLE PLAYERDATA (NAME TEXT PRIMARY KEY NOT NULL, POINTS INT DEFAULT 0 NOT NULL);
    sqlite> INSERT OR IGNORE INTO PLAYERDATA (NAME, POINTS) VALUES ('a', 1), ('b', 2);
    sqlite> SELECT * FROM PLAYERDATA;
    a|1
    b|2
    sqlite>

    Last edited: Sep 29, 2015

  7. @Resolver

    Why don’t you use VALUES (‘a’, ‘b’)? Like I can’t understand what sort of relation you’re trying to represent.

    1. [18:29:36 WARN]: at ye.reproduce.output.MainClass.onEnable(MainClass.java:33)

    Please post this line of code.

    EDIT: Never mind found it.

    That’s not proper MySQL code I believe…

  8. Right, I’m sorry my table sounds vaguely presented. So I created a table that stores player’s name (text) and their points (int). That’s it and only it for now. I want to insert multiple columns in one line. Which should be fine in SQLite with:

    INSERT OR IGNORE INTO TABLENAME (NAME, POINTS) VALUES ('playername1', 1500), ('playername2', 2500);

    I’ve done this before and I’m sure it executed properly without any error. But when I do it again this time, it returns an error. The error is located near ‘,’ (at NAME,POINTS)I’m using SQLite. And it’s a proper SQLite code I believe.

  9. Were you able to check the sqlite version already, which your plugin is using, as I suggested above? (run the query «select sqlite_version();»)

  10. It returns 3.7.2

    try {
       if (sql.open()){
         getLogger().log(Level.INFO, sql.query("SELECT sqlite_version();").getString(1));
      }
    } catch (SQLException e) {
       e.printStackTrace();
    } finally {
       sql.close();
    }

    EDIT: I’m marking this as solved because the sqlite version doesn’t support inserting multiple rows (needs to be above 3.7.11). I was pretty sure that I’ve done that before and it was working. But now I’m confused.

    Thanks, everyone!

    Last edited: Sep 30, 2015

Thread Status:

Not open for further replies.

Share This Page


Bukkit Forums

Waldemar Lima


  • #1

hello everyone !

I am experiencing this error when updating the table again …

Waiting for debugger to connect...
Program started.
---------- NorthWind Database (MySQL) ----------

Error occurred on line: 635 (B4XTable)
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
    at org.sqlite.DB.newSQLException(DB.java:383)
    at org.sqlite.DB.newSQLException(DB.java:387)
    at org.sqlite.DB.throwex(DB.java:374)
    at org.sqlite.NativeDB.prepare(Native Method)
    at org.sqlite.DB.prepare(DB.java:123)
    at org.sqlite.Stmt.execute(Stmt.java:113)
    at anywheresoftware.b4j.objects.SQL.ExecNonQuery(SQL.java:156)
    at b4j.example.b4xtable._createtable(b4xtable.java:2035)
    at b4j.example.b4xtable$ResumableSub_SetData.resume(b4xtable.java:473)
    at b4j.example.b4xtable._setdata(b4xtable.java:412)
    at b4j.example.main$ResumableSub_MySQL_Ready.resume(main.java:1272)
    at b4j.example.main._mysql_ready(main.java:854)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$3.run(BA.java:247)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)

b4j code >

Dim ApostasData As List
            ApostasData.Initialize
            '
            
            Dim RS As ResultSet = SQL.ExecQuery($"select a.id, CONCAT(b.equipeCasa,' x ',b.equipeFora) , b.campeonato , CONCAT(b.dataP,' ás ', b.horarioP) , c.nome , a.apostadorNome , a.apostado , a.tipo
            from
            apostas a
            inner join
            cambistas c
            on a.cambistaId = c.id
            inner join
            partidas b
            on a.partidaId = b.id"$)
            'WHERE dataA='"&$Date{DateTime.Now}&"';"$)
            
            'Dim RS As ResultSet = SQL.ExecQuery("SELECT * FROM apostas WHERE dataA='"&DateTime.Date(DateTime.Now)&"';")
            Log(DateTime.Date(DateTime.Now))
                Do While RS.NextRow

                    Dim row(8) As Object
                    row(0) = RS.GetString2(0)
                    row(1) = RS.GetString2(1)
                    row(2) = RS.GetString2(2)
                    row(3) = RS.GetString2(3)
                    row(4) = RS.GetString2(4)
                    row(5) = RS.GetString2(5)
                    row(6) = RS.GetString2(6)
                    row(7) = RS.GetString2(7)
                    ApostasData.Add(row)
              
                Loop
                
                RS.Close
            Log("Chega aqui !")
            B4XTable1.SetData(ApostasData)
            HideLoading
            MenuBar1.Enabled = True

Erel


  • #2

Have you added 8 columns?

rraswisak


  • #3

java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near «)»: syntax error)

CONCAT function is not supported in SQLite, use || instead, so your sql should look like this:

CONCAT(b.equipeCasa,’ x ‘,b.equipeFora) change to: (b.equipeCasa || ‘ x ‘ || b.equipeFora)

Last edited: Nov 5, 2019

Waldemar Lima


  • #4

Have you added 8 columns?

how can i clear just items from B4XTable without clear columns ?

Waldemar Lima


  • #5

CONCAT function is not supported in SQLite, use || instead, so your sql should look like this:

CONCAT(b.equipeCasa,’ x ‘,b.equipeFora) change to: (b.equipeCasa || ‘ x ‘ || b.equipeFora)

changed, thanks :D

Erel


  • #6

Call SetData without calling Clear.

Waldemar Lima


Понравилась статья? Поделить с друзьями:
  • Sql error near table syntax error
  • Sql error mysqli connection refused 2002
  • Sql error message oracle
  • Sql error library routine called out of sequence
  • Sql error invalid cursor