在MySQL Workbench中,您可以向MySQL数据库中的表和列添加注释.
Sqlite是否支持向表和列添加注释?
我需要记录查询,不仅是插入/更新/删除,还要从使用SQLite的许多应用程序中选择和其他查询.在这种情况下,向应用程序引入日志记录在实践中不是可行的解决方案.那么如何在SQLite本身启用查询日志记录呢?
我有这个查询,它在MySQL中运行良好
SELECT ((ACOS(SIN(12.345 * PI() / 180) * SIN(lat * PI() / 180) +
COS(12.345 * PI() / 180) * COS(lat * PI() / 180) * COS((67.89 - lon) *
PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) AS distance, poi.*
FROM poi
WHERE lang='eng'
HAVING distance<='30'
Run Code Online (Sandbox Code Playgroud)
距离以公里为单位,输入为lat=12.345和lon=67.89
SQLite是3,我无法在Android上运行自定义函数.我也没有acos()等......因为它不是标准SQLite的一部分.
如何在SQLite中进行上述查询?
我想做的是以下几点:
using System.Data.SQLite;
using System.IO;
//My SQLite connection
SQLiteConnection myCon;
public void ReadAndOpenDB(string filename)
{
FileStream fstrm = new FileStream(filename, FileMode.Open);
byte[] buf = new byte[fstrm.Length];
fstrm.Read(buf, 0, (int)fstrm.Length);
MemoryStream mstrm = new MemoryStream(buf);
//Do some things with the memory stream
myCon = new SQLiteConnection(/*attach to my memory stream for reading*/);
myCon.Open();
//Do necessary DB operations
}
Run Code Online (Sandbox Code Playgroud)
我不打算写入内存数据库,但我需要能够在连接到程序之前在程序的内存中对文件做一些事情.
我有以下DB帮助程序类:
public int studentExists(String studid) {
Cursor dataCount = mDb.rawQuery("select count(*) from usertable where " + KEY_STUDID + "=" + studid, null);
dataCount.moveToFirst();
int count = dataCount.getInt(0);
dataCount.close();
return count;
}
Run Code Online (Sandbox Code Playgroud)
我在我的应用程序中使用此功能来查看之前是否已输入学生ID.
当学生ID是整数时(346742),这样可以正常工作,但每当我尝试添加字母数字ID(PB3874)时,它会强制关闭应用程序.
错误:
06-13 18:22:20.554:ERROR/AndroidRuntime(8088):android.database.sqlite.SQLiteException:没有这样的列:pb3874 :,编译时:从usertable中选择count(*)其中studid = pb3874
我不认为它是一个数据类型问题(因为我使用文本类型):
private static final String DATABASE_CREATE =
"create table usertable (_id integer primary key autoincrement, "
+ "studid text not null);";
Run Code Online (Sandbox Code Playgroud)
但我很困惑为什么错误说,no such column: pb3874因为我试图从studid列中简单地选择该值.以及为什么这适用于任何int值.任何人有任何解决建议的问题?
我创建了一个数据库,并提交了数据.有一列我想找到最大的价值.
这是我的数据库适配器中使用的方法:
public Cursor getBiggestInTheColumn() {
return db.query(DATABASE_TABLE, null,
"MAX(price)", null, null, null, null);
}
Run Code Online (Sandbox Code Playgroud)
它应该工作,但当我调用方法时:
cursor = dbadp.getBiggestInTheColumn();
Run Code Online (Sandbox Code Playgroud)
我得到像这样的运行时错误(LogCat):
07-14 12:38:51.852:ERROR/AndroidRuntime(276):引起:android.database.sqlite.SQLiteException:滥用聚合函数MAX():,同时编译:SELECT*FROM花费WHERE MAX(价格)
有任何想法吗?我怀疑这是由于查询错误,但这是我能想到的最好的.其他查询运作良好.
我正在使用Visual Studio的新Node.js工具,并包含sqlite3 npm模块.当我调用require('sqlite3')它时会抛出错误:
Error: Cannot find module './binding\Debug\node-v11-win32-ia32\node_sqlite3.node'
奇怪的是,当我忽略错误并继续运行代码时,一切正常......直到我所处的函数返回; 然后服务器崩溃了.
其他人遇到过这个问题吗?我怀疑它与./binding部件有关,但不知道从哪里开始找出原因.
我正在使用SQLiteOpenHelper进行数据插入.我需要插入2500个id和2500个名字,所以需要花费太多时间.请任何人帮我如何减少插入时间.我们可以一次插入多个记录吗?任何人帮助我.先感谢您.码:
public class DatabaseHandler extends SQLiteOpenHelper {
SQLiteDatabase db;
private static final int DATABASE_VERSION = 8;
private static final String TABLE_CITY = "CITYDETAILS";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.mContext = context;
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CITY );
String CREATE_CITY_TABLE = "CREATE TABLE " + TABLE_CITY + "("
+ CityId + " INTEGER," + CityName + " TEXT " + ")";
db.execSQL(CREATE_CITY_TABLE);
db.execSQL(CREATE_RechargeTypes_TABLE);
this.db=db;
}
@Override
public void onUpgrade(SQLiteDatabase db, …Run Code Online (Sandbox Code Playgroud) 我有一个表示安全摄像机NVR元数据的数据库.recording每1分钟的视频片段有一个26字节的行.(如果你很好奇,一个设计文档正在进行这里.)我的设计限制是8个摄像头,1年(约4万行,半一万元左右的相机).我已经伪造了一些数据来测试性能.此查询比我预期的要慢:
select
recording.start_time_90k,
recording.duration_90k,
recording.video_samples,
recording.sample_file_bytes,
recording.video_sample_entry_id
from
recording
where
camera_id = ?
order by
recording.start_time_90k;
Run Code Online (Sandbox Code Playgroud)
这只是扫描相机的所有数据,使用索引过滤掉其他相机和订购.索引看起来像这样:
create index recording_camera_start on recording (camera_id, start_time_90k);
Run Code Online (Sandbox Code Playgroud)
explain query plan 看起来像预期:
0|0|0|SEARCH TABLE recording USING INDEX recording_camera_start (camera_id=?)
Run Code Online (Sandbox Code Playgroud)
行很小.
$ sqlite3_analyzer duplicated.db
...
*** Table RECORDING w/o any indices *******************************************
Percentage of total database...................... 66.3%
Number of entries................................. 4225560
Bytes of storage consumed......................... 143418368
Bytes of payload.................................. 109333605 76.2%
B-tree depth...................................... 4
Average payload per entry......................... 25.87
Average unused …Run Code Online (Sandbox Code Playgroud) Java.lang.IllegalStateException
迁移没有正确处理用户(therealandroid.github.com.roomcore.java.User).
预期:
TableInfo {name ='user',columns = {name = Column {name ='name',type ='TEXT',notNull = false,primaryKeyPosition = 0},age = Column {name ='age',type ='INTEGER ',notNull = true,primaryKeyPosition = 0},id = Column {name ='id',type ='INTEGER',notNull = true,primaryKeyPosition = 1}},foreignKeys = []}找到:
发现
TableInfo {name ='user',columns = {name = Column {name ='name',type ='TEXT',notNull = false,primaryKeyPosition = 0},id = Column {name ='id',type ='INTEGER ',notNull = true,primaryKeyPosition = 1},age = Column {name ='age',type ='INTEGER',notNull = false,primaryKeyPosition = 0}},foreignKeys = []}
我正在尝试执行一个简单的迁移,我有一个被调用的类User,它有两列ID (primary key) …
sqlite ×10
android ×5
sql ×2
android-room ×1
c# ×1
comments ×1
connection ×1
javascript ×1
logging ×1
metadata ×1
node.js ×1
npm ×1
performance ×1