在进入全速开发模式之前,我正在玩一些基本的东西在Python中工作.以下是具体内容:
Python 2.5.4
PyQt4 4.4.3
SqlAlchemy 0.5.2
py2exe 0.6.9
setuptools 0.6c9
pysqlite 2.5.1
Run Code Online (Sandbox Code Playgroud)
setup.py:
from distutils.core import setup
import py2exe
setup(windows=[{"script" : "main.py"}], options={"py2exe" : {"includes" : ["sip", "PyQt4.QtSql","sqlite3"],"packages":["sqlite3",]}})
Run Code Online (Sandbox Code Playgroud)
py2exe似乎正确生成.exe文件,但是当我执行dist/main.exe时,我在main.exe.log中得到了这个
Traceback (most recent call last):
File "main.py", line 18, in <module>
File "main.py", line 14, in main
File "db\manager.pyc", line 12, in __init__
File "sqlalchemy\engine\__init__.pyc", line 223, in create_engine
File "sqlalchemy\engine\strategies.pyc", line 48, in create
File "sqlalchemy\engine\url.pyc", line 91, in get_dialect
ImportError: No module named sqlite
Run Code Online (Sandbox Code Playgroud)
我一直在谷歌上搜索,但似乎无法找到任何解决方案.如果我现在无法使用它,我希望在这个项目中使用Python将会破灭,我将重新开始使用Ruby ...(不是说Ruby有什么问题,我只是想把这个项目用作自学Python的好方法)
我有一张包含这些数据的表格
id , name , description
1 , apple , ''
2 , orange , ''
Run Code Online (Sandbox Code Playgroud)
我试图传递以下语句来更新行,所以描述列是'desc of apple'和'desc of orange'但它不起作用.
Update TestTable Set description = 'desc of ' + name
Run Code Online (Sandbox Code Playgroud)
连接字符串的正确语法是什么?
以下作品:
>>> cursor.execute("select * from sqlitetable where rowid in (2,3);")
Run Code Online (Sandbox Code Playgroud)
以下不是:
>>> cursor.execute("select * from sqlitetable where rowid in (?) ", [[2,3]] )
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
Run Code Online (Sandbox Code Playgroud)
有没有办法传入python列表而不必先将其格式化为字符串?
可能重复:
Android备份/恢复:如何备份内部数据库?
我正在开发一个有SQL lite db的应用程序.我需要让用户能够备份数据库并再次恢复它.我怎样才能做到这一点?示例代码?
如果我的用户保存了数据库,然后将应用程序升级到新的数据库版本代码,还原工作?我该怎么做?
我正在尝试种下一组足球队和足球队的位置,铁杆奇怪的是根本就没有这样做.
rake db:seed --trace
** Invoke db:seed (first_time)
** Execute db:seed
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:abort_if_pending_migrations
Run Code Online (Sandbox Code Playgroud)
一切看起来都不错,但是当我提起我的网站时(之前正在使用peachy,我知道那里不是代码)没有记录.
我正在加载三个对象:团队,玩家和职位.有趣的是,当我做出一个新的团队,有没有字段,但是当我去创建一个新的球员,也有各个领域.
Seeds.rb看起来像这样:
position = Position.create(:positionName => 'Quarterback', :positionShort => 'QB', :stance => 'offense')
team = Team.create( name:'Patriots', location:'New England', conference:'AFC', division:'East', wins:'5', losses:'3')
Run Code Online (Sandbox Code Playgroud)
让我知道你还需要看到什么,我处在一个缺乏经验和无法解释的错误的十字路口.
是否可以从现有应用程序中完全删除数据库和所有迁移记录等,以便我可以从头开始重新设计数据库?
database sqlite activerecord rails-migrations ruby-on-rails-3
我试图以编程方式创建一个sqlite db,如果它不存在.我写了下面的代码但是我在最后一行得到了一个例外.
if (!System.IO.File.Exists("C:\\Users\\abc\\Desktop\\1\\synccc.sqlite"))
{
Console.WriteLine("Just entered to create Sync DB");
SQLiteConnection.CreateFile("C:\\Users\\abc\\Desktop\\1\\synccc.sqlite");
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, sqlite2);
command.ExecuteNonQuery();
}
sqlite2 = new SQLiteConnection("Data Source=C:\\Users\\abc\\Desktop\\1\\synccc.sqlite");
Run Code Online (Sandbox Code Playgroud)
我在行中得到异常command.ExecuteNonQuery();异常是Invalid operation exception was unhandled.有没有其他方法可以将sqlite文件添加到您的项目中?我可以手动完成吗?如果没有,那么我该如何解决上述问题呢?
如SQLite文档中所述,可以使用:
sqlite> .timer ON
Run Code Online (Sandbox Code Playgroud)
或者向〜/ .sqliterc添加相同的命令
完成此操作后,SQLite shell将为每个执行的查询响应CPU时间的用户和sys组件:
user@machine% sqlite3 test.db
-- Loading resources from ~/.sqliterc
SQLite version 3.7.14 2012-09-03 15:42:36
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select count(*) from my_table;
count(*)
10143270
CPU Time: user 0.199970 sys 1.060838
Run Code Online (Sandbox Code Playgroud)
虽然我发现这个答案提供了时间单位的证据,但是我很难同意它.当使用秒表计时执行查询时,我发现几乎所有查询都需要花费的时间超过shell的时间.例如,在上面的例子中定时查询大约花了1分54秒实时.造成这种差异的原因是什么?
再一次,这些单位是什么?什么是用户和sys组件?
我在可通过NFS访问的Debian GNU/Linux 6.0.6(squeeze)发行版上运行SQLite 3.7.14.
官方文件指出:
It is recommended to have multiple Dao classes in your codebase depending on the tables they touch.
Run Code Online (Sandbox Code Playgroud)
并且可以使用Transaction注释标记方法,如下所示:
@Dao
public abstract class ProductDao {
@Insert
public abstract void insert(Product product);
@Delete
public abstract void delete(Product product);
@Transaction
public void insertAndDeleteInTransaction(Product newProduct, Product oldProduct) {
// Anything inside this method runs in a single transaction.
insert(newProduct);
delete(oldProduct);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果一个事务跨越多个DAO怎么办?我应该将所有DAO合并为一个只是为了支持交易,还是有更好的方法来做到这一点?
sqlite ×10
android ×2
python ×2
.net ×1
activerecord ×1
android-room ×1
c# ×1
dao ×1
database ×1
linux ×1
persistence ×1
php ×1
py2exe ×1
ruby ×1
sql ×1
sqlalchemy ×1
syntax ×1