- 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 errorI 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
-
Proposed as answer by
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.17
(or put your version here)
Steps to reproduce or a small repository showing the problem:
repo : https://github.com/5minlab/typeorm-sqlite-simple-enum-bug
- create new typeorm project. I use
typeorm init
- use simple-enum. I modify
src/entity/User.ts
export enum UserType { Normal = "normal", Admin = "admin", } @Entity() export class User { .... @Column({ type: "simple-enum", enum: UserType, }) ty: UserType; }
- use sqlite, enable sychronize in ormconfig.json, execute twice.
first execution, working well.
PS F:bugtypeorm-sqlite-simple-enum-bug> npm run start
> sqlite-simple-enum@0.0.1 start F:bugtypeorm-sqlite-simple-enum-bug
> ts-node src/index.ts
Inserting a new user into the database...
Saved a new user with id: 1
Loading users from the database...
Loaded users: [ User {
id: 1,
firstName: 'Timber',
lastName: 'Saw',
age: 25,
ty: 'admin' } ]
Here you can setup and run express/koa/any other framework.
second execution, not working.
SQLITE_ERROR: near "-": syntax error
.
simple-enum
is included in SQL.
PS F:bugtypeorm-sqlite-simple-enum-bug> npm run start
> sqlite-simple-enum@0.0.1 start F:bugtypeorm-sqlite-simple-enum-bug
> ts-node src/index.ts
{ QueryFailedError: SQLITE_ERROR: near "-": syntax error
at new QueryFailedError (F:bugtypeorm-sqlite-simple-enum-bugsrcerrorQueryFailedError.ts:9:9)
at handler (F:bugtypeorm-sqlite-simple-enum-bugsrcdriversqliteSqliteQueryRunner.ts:53:26)
at replacement (F:bugtypeorm-sqlite-simple-enum-bugnode_modulessqlite3libtrace.js:19:31)
at Statement.errBack (F:bugtypeorm-sqlite-simple-enum-bugnode_modulessqlite3libsqlite3.js:16:21)
message: 'SQLITE_ERROR: near "-": syntax error',
errno: 1,
code: 'SQLITE_ERROR',
name: 'QueryFailedError',
query:
'CREATE TABLE "temporary_user" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "firstName" varchar NOT NULL, "lastName" varchar NOT NULL, "age" integer NOT NULL, "ty" simple-enum CHECK( ty IN ('normal','admin') ) NOT NULL)',
parameters: [] }
I modify src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts
to fix bug.
but I can’t trust my approach.
5minlab@ed4e91d
Я пытаюсь создать таблицу с помощью anko
библиотеки в kotlin
, как показано ниже
override fun onCreate(db: SQLiteDatabase?) {
db!!.createTable(PersonTable.Name, true,
Pair(PersonTable.ID, INTEGER + PRIMARY_KEY + AUTOINCREMENT),
Pair(PersonTable.PersonName, TEXT),
Pair(PersonTable.Domain, TEXT),
Pair(PersonTable.MobileNumber, REAL))
}
Когда я добавляю AUTOINCREMENT
к ID, я становлюсь ниже ошибки. Он работает без AUTOINCREMENT
. Каким образом можно сделать любой атрибут AUTOINCREMENT
с помощью библиотеки anko
.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.williamsro.fourthdemo, PID: 4799
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.williamsro.fourthdemo/com.williamsro.fourthdemo.MainActivity}: android.database.sqlite.SQLiteException: near "org": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS 'Person'(id INTEGER PRIMARY KEY [email protected], person_name TEXT, domain TEXT, mobile_number REAL);
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.database.sqlite.SQLiteException: near "org": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS 'Person'(id INTEGER PRIMARY KEY [email protected], person_name TEXT, domain TEXT, mobile_number REAL);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1675)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1606)
at org.jetbrains.anko.db.DatabaseKt.createTable(Database.kt:80)
at com.williamsro.fourthdemo.AppDbHelpler.onCreate(AppDbHelpler.kt:17)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at org.jetbrains.anko.db.ManagedSQLiteOpenHelper.openDatabase(Database.kt:166)
at org.jetbrains.anko.db.ManagedSQLiteOpenHelper.use(Database.kt:157)
at com.williamsro.fourthdemo.MainActivity.insertPerson(MainActivity.kt:44)
at com.williamsro.fourthdemo.MainActivity.onCreate(MainActivity.kt:72)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)