我有两个整数,它们是表中两个现有行的一些 ID。
我想要做的是只交换两行的值,除了它们的 ID。
例如,如果我给出了 ID 5 和 13,我想更改
ID columnA columnB columnC
5 343 "ABC" null
13 90 "DEF" "ZY"
Run Code Online (Sandbox Code Playgroud)
进入
ID columnA columnB columnC
5 90 "DEF" "ZY"
13 343 "ABC" null
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?ID 列不是 AUTO-INCREMENT,所以我不能鲁莽地插入具有任意 ID 的临时行。
是否可以在 Mozilla、chrome、IE 和 safari 等网络浏览器上使用本地 SQLite db。我的意思是,我可以将本地 SQLite db 用于 Web 应用程序吗?如果否,请建议替代本地数据库。
在此处将数据插入 sqlite 时出错是堆栈跟踪
E/SQLiteDatabase: Error inserting addhar_number=test profile_pic=null token=null name=Nikhil Patil email=niks34547@gmail.com phone= profile_pic_bg=null gender=test birthday=test
android.database.sqlite.SQLiteException: table user has no column named addhar_number (code 1): , while compiling: INSERT INTO user(addhar_number,profile_pic,token,name,email,phone,profile_pic_bg,gender,birthday) VALUES (?,?,?,?,?,?,?,?,?)
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.insertWithOnConflict(SQLiteDatabase.java:1472)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1343)
at com.wowoni.bikesharing.bicyclesharing.Helper.SQliteHandler.addUser(SQliteHandler.java:88)
at com.wowoni.bikesharing.bicyclesharing.activity.HomeActivity.loadNavHeader(HomeActivity.java:227)
at com.wowoni.bikesharing.bicyclesharing.activity.HomeActivity.onCreate(HomeActivity.java:129)
at android.app.Activity.performCreate(Activity.java:6684)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2652)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2766)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891) …Run Code Online (Sandbox Code Playgroud) 我使用 EntityFrameworkCore 2.0 将Name实体中的一个属性UnitType设置为 SQLite 的唯一性。
modelBuilder.Entity<UnitType>().HasIndex(t => t.Name).IsUnique();
Run Code Online (Sandbox Code Playgroud)
但它的行为区分大小写。意味着它将Gram和gram视为两个不同的值并插入它们。在我花了大量时间在 MS-SQL 上之后,这显然不是所期望的。
此外,另一个问题是过滤此列上的数据时。即使那是区分大小写的。
db.Units.Where(w => w.Name.Contains(SearchText));
Run Code Online (Sandbox Code Playgroud)
如何使它不区分大小写?
我有 FTS 表和查询,它匹配列包含“all”和“in”的所有行。
try db.executeQuery("SELECT * FROM table WHERE column MATCH '\"all\" AND \"in\"'", values: nil)
Run Code Online (Sandbox Code Playgroud)
如何使用参数绑定使其工作?所以我可以提供:
values: ["all", "in"]
Run Code Online (Sandbox Code Playgroud) 当我在 Android 上从旧的 sqlite 方式迁移到 Room 时,我需要使用“INTEGER NOT NULL”进行编译。问题是,当迁移发生时,您正在使用“NOT NULL”参数在新表中插入 NULL 字段,但出现错误
android.database.sqlite.SQLiteConstraintException:NOT NULL 约束失败:note.notification_state(代码 1299)
编辑:
11-29 22:52:58.891 14605-14630/com.aleksandarvasilevski.notes E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
Process: com.aleksandarvasilevski.notes, PID: 14605
java.lang.IllegalStateException: Migration didn't properly handle note(com.aleksandarvasilevski.notes.repository.db.Note).
Expected:
TableInfo{name='note', columns={notification_date=Column{name='notification_date', type='TEXT', notNull=false, primaryKeyPosition=0}, priority=Column{name='priority', type='INTEGER', notNull=true, primaryKeyPosition=0}, description=Column{name='description', type='TEXT', notNull=false, primaryKeyPosition=0}, title=Column{name='title', type='TEXT', notNull=false, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', notNull=true, primaryKeyPosition=1}, notification_state=Column{name='notification_state', type='INTEGER', notNull=true, primaryKeyPosition=0}, created_date=Column{name='created_date', type='TEXT', notNull=false, primaryKeyPosition=0}}, foreignKeys=[], indices=[]}
Found:
TableInfo{name='note', columns={notification_date=Column{name='notification_date', type='TEXT', notNull=false, primaryKeyPosition=0}, priority=Column{name='priority', type='INTEGER', notNull=false, primaryKeyPosition=0}, title=Column{name='title', type='TEXT', notNull=false, primaryKeyPosition=0}, …Run Code Online (Sandbox Code Playgroud) 根据文档,
连接对象可用作自动提交或回滚事务的上下文管理器。发生异常时,事务回滚;否则,事务被提交:
我知道with语句中的所有内容都应该是原子事务。现在考虑这个代码
import sqlite3
con = sqlite3.connect(':memory:')
try:
with con:
con.execute('create table foo (id integer primary key)')
con.execute('insert into foo values (1)')
con.execute('insert into foo values (1)')
except sqlite3.Error:
print('transaction failed')
try:
rec = con.execute('select count(*) from foo')
print('number of records: {}'.format(rec.fetchone()[0]))
except sqlite3.Error as e:
print(e)
Run Code Online (Sandbox Code Playgroud)
返回
import sqlite3
con = sqlite3.connect(':memory:')
try:
with con:
con.execute('create table foo (id integer primary key)')
con.execute('insert into foo values (1)')
con.execute('insert into foo values (1)')
except sqlite3.Error:
print('transaction …Run Code Online (Sandbox Code Playgroud) 蟒蛇 3.6。我正在尝试为 sqlite3 创建一个 REGEXP 函数。我有错误:OperationalError: wrong number of arguments to function REGEXP()
这是我的代码:
import sqlite3
import re
def fonctionRegex(mot):
patternRecherche = re.compile(r"\b"+mot.lower()+"\\b")
return patternRecherche.search(item) is not None
dbName = 'bdd.db'
connexion = sqlite3.connect(dbName)
leCursor = connexion.cursor()
connexion.create_function("REGEXP", 1, fonctionRegex)
mot = 'trump'
data = leCursor.execute('SELECT * FROM tweet WHERE texte REGEXP ?',mot).fetchall()
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在运行 Laravel 5.2,在 Windows 8.1 上使用 XAMPP 和 php 7.2,我正在尝试使用带有 sqlite 数据库的 laravel auth 注册表来注册用户。但是,当我尝试将新记录插入表时users,出现错误。
SQLSTATE[HY000]:一般错误:1 没有这样的表:用户
当我迁移数据库时,它会创建用户表。但是当我尝试users使用注册表在表中插入新记录时,它会尝试访问user表。所以我user在数据库中创建了表,它工作正常,但记录插入到users表中而不是user表中。
移民
public function up(){
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('name');
$table->string('role');
$table->string('username');
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down(){
Schema::drop('users');
}
Run Code Online (Sandbox Code Playgroud)
用户模型
class User extends Authenticatable{
protected $primaryKey = 'user_id';
protected $fillable = [
'name', 'role', 'username', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
Run Code Online (Sandbox Code Playgroud)
身份验证控制器 …
这是我要执行的以下 sql 查询,并且在命令行上完美运行:
select * from table1 join table2 using (col1, col2)
我无法弄清楚如何使用 SQLAlchemy 执行此操作,任何帮助将不胜感激。
表之间没有外键。表行只能通过多列中匹配的值配对。
谢谢!
sqlite ×10
python ×3
sql ×3
android ×2
android-architecture-components ×1
android-room ×1
c# ×1
fmdb ×1
ios ×1
laravel ×1
php ×1
python-3.x ×1
sqlalchemy ×1
swap ×1
swift ×1