简体   繁体   English

我如何在我的飞镖代码中解决此问题

[英]How Can I Solve This Problem in my dart code sqlite

I have a problem in my code that occurs error in lunching in database_helper.dart 我的代码中有一个问题,在database_helper.dart中午餐时发生错误

database_helper.dart is one file in Sqlite storing data learning project and i faced this issue , i tried many solutions like uninstall app and install it again database_helper.dart是Sqlite中存储数据学习项目的一个文件,我遇到了此问题,我尝试了许多解决方案,例如卸载应用程序并重新安装

can any one help me ? 谁能帮我 ?

======

  class DataBaseHelper {
    static Database _db ;
    final String userT = 'userT' ;
    final String columnId = 'id' ;
    final String columnUserName = 'username' ;
    final String columnPassword = 'password' ;
    final String columnAge = 'age' ;
    final String columnCity = 'city' ;
=========

  Future<Database> get dbase async {
    if(_db != null) {
      return _db ;
    }
    _db = await intDB();
    return _db ;

  }
=================

  intDB() async {
    Directory docDirectory = await getApplicationDocumentsDirectory() ;
    String path = join(docDirectory.path , 'myDB.db') ;
    var myOwnDB = await openDatabase(path , version: 1 , onCreate: _onCreate);
    return myOwnDB ;
  }
=========================

  void _onCreate(Database db , int newVersion) async {
    var sql = 'CREATE TABLE $userT ($columnId INTEGER PRIMARY KEY UNIQUE ,'
        ' $columnUserName TEXT , $columnPassword TEXT , $columnCity TEXT , $columnAge INTEGER ' ;
    await db.execute(sql) ;
  }

error log: 错误日志:

E/SQLiteLog(14607): (1) near "INTEGER": syntax error E / SQLiteLog(14607):“ INTEGER”附近的(1):语法错误

I/flutter (14607): error DatabaseException(near "INTEGER": syntax error (code 1): , while compiling: CREATE TABLE userT (id INTEGER PRIMARY KEY UNIQUE , username TEXT , password TEXT , city TEXT , age INTEGER) during oenter code herepen, closing... I / flutter(14607):错误DatabaseException(在“ INTEGER”附近:语法错误(代码1):),而在编译时:Centate table userT(id INTEGER主键唯一性,用户名TEXT,密码TEXT,city TEXT,age INTEGER)代码herepen,关闭...

E/flutter (14607): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: DatabaseException(near "INTEGER": syntax error (code 1): , while compiling: CREATE TABLE userT (id INTEGER PRIMARY KEY UNIQUE , username TEXT , password TEXT , city TEXT , age INTEGER) E / flutter(14607):[错误:flutter / lib / ui / ui_dart_state.cc(148)]未处理的异常:DatabaseException(在“ INTEGER”附近:语法错误(代码1):,而在编译时:CREATE TABLE userT(id INTEGER主键唯一性,用户名TEXT,密码TEXT,城市TEXT,年龄INTEGER)

Syntax error. 语法错误。 you forgot to put ) at the end of line 您忘了把)放在行尾

$columnAge INTEGER )

You can check your sqllite code in https://sqliteonline.com/ 您可以在https://sqliteonline.com/中检查您的sqllite代码

CREATE TABLE userT (columnId INTEGER PRIMARY KEY UNIQUE ,
        columnUserName TEXT , columnPassword TEXT , columnCity TEXT , columnAge INTEGER)

after put ) . 放置后)。 it works fine. 它工作正常。

在此处输入图片说明

Edit : Second question of Insert Into statement you mentioned in comments 编辑:您在评论中提到的Insert Into语句的第二个问题

The syntax error of Insert Into statement is column "userCity" does not exist. Insert Into语句的语法错误是“ userCity”列不存在。
In the question you provided, when Create table you use the name columnCity = 'city'. 在您提供的问题中,在创建表时,使用名称columnCity ='city'。 so you sholud change the name to "city". 因此,您应该将名称更改为“ city”。

Try removing UNIQUE 尝试删除唯一

They have not included that word in any of the samples, so maybe it has not been implemented. 他们没有在任何示例中包含该词,因此可能尚未实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM