每当我尝试使用python和sqlite3创建表时,它会给我以下错误:
Traceback (most recent call last)
File "directory.py", line 14, in <module>
'Children' TEXT, 'Other' TEXT, 'Masul' TEXT);''')
sqlite3.OperationalError: near ")": syntax error
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建表的方式是:
conn.execute('''create table Jamaat
(id integer primary key,
Email TEXT,
LastName TEXT,
Address1 TEXT,
Apt TEXT,
Address2 TEXT,
City TEXT,
State TEXT,
Zip TEXT,
HomePhone TEXT,
FaxNumber TEXT,
Primary TEXT,
Spouse TEXT,
Children TEXT,
Other TEXT,
Masul TEXT);''')
conn.commit()
Run Code Online (Sandbox Code Playgroud)
我正在使用python 2.7并尝试将csv电子表格导入sqlite3
在此先感谢编辑:我已经尝试了没有尾随逗号的代码,但它仍然无效...
我的sqlite在其中一个实体中有项目,我希望根据它们的categoryID检索它们
例如,categoryID 1有7个项目,categoryID 2有5个项目,当我点击IBAction时,它会转到这个方法并根据我的global.clickedTag检索
但我无法检索值,任何想法为什么?
-(NSMutableArray*)fetchItem:array{
[self managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"IItem" inManagedObjectContext:managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
//filter here
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"categoryID == %i",myGlobal.clickedTag];
[request setPredicate:predicate];
[request setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ID" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
NSError *error;
NSMutableArray* mutableFetchCategory = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (!mutableFetchCategory) {
// Handle the error.
}
if ([mutableFetchCategory count] > 0)
{
for (NSManagedObject *info in mutableFetchCategory)
{
if …Run Code Online (Sandbox Code Playgroud) 我试图找到一种方法来了解使用python时是否从SQLite查询返回了一些值.
conn = sqlite3.connect('/path/to/database.db')
cursor=conn.cursor()
t=(value,)
cursor.execute("select field from table where other_field = ?", t)
returnObject = cursor.fetchone()[0]
Run Code Online (Sandbox Code Playgroud)
如果表确实包含匹配值,那么它将存储在returnObject.
如果数据库没有与请求匹配的任何条目,则会出现问题.在那种情况下,我得到一个exceptions.TypeError: unsubscriptable object
除了将整个块放在try/expect块中之外,还有一种方法可以知道数据库是否返回了某些内容.
此外,我知道我可以发出额外的查询,但这会使连接过于繁琐.
我的问题是如何设计数据库.
我有一个表,称为帖子,有列:
ID, subject, keywords, (and a few other columns)
Run Code Online (Sandbox Code Playgroud)
和另一个名为关键字的表:
kw_id, keyword.
Run Code Online (Sandbox Code Playgroud)
现在,每个"帖子"都有几个关键字,有时会删除关键字,因为它们没有意义或是重复的.
我的问题是:
可以关键字表列的职位是一个外键?(每行都有多个关键字)
如果我不能,那么确保数据完整性的最佳方法是什么(特别是在删除关键字时)?
提前致谢
编辑:你能指出我应该阅读的关于数据库设计的书籍或文件吗?我似乎在关注数据库设计的关键知识.
我有一个测试项目,我试图使用sql lite内存数据库测试我的nhibernate层.
我收到错误:
无法从NHibernate.Driver.SQLite20Driver,NHibernate,Version = 3.1.0.4000创建驱动程序,
private void CreateSessionFactory()
{
_sessionFactory = Fluently
.Configure()
.Database(_dbType)
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<UserMap>())
.ExposeConfiguration(cfg => _configuration = cfg)
.BuildSessionFactory();
}
Run Code Online (Sandbox Code Playgroud)
我正在使用fluentnhibernate和nunit.
问题可能是什么?
更新
我从http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki下载了x64(我在Windows 7 64位上) ,现在我收到了这个错误:
Unable to load DLL 'SQLite.Interop.DLL': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Run Code Online (Sandbox Code Playgroud)
如果我尝试在vs.net 2010中添加Interop.dll,它不会让我说它无法添加,请确保它是有效的等.
如何在android sqlite查询语句中传递两个参数?
我的查询看起来像这样,但我收到错误.如果我使用一个条件其工作正常,但我想使用两个条件.
db.query(true, DB_TABLE, new String[] {KEY_ROWID,Source,
Dest}, DestStn + "=" + t ,Source + "=" +tt,null,
null, null, null, null);
Run Code Online (Sandbox Code Playgroud) 我使用Python和Sqlalchemy在Sqlite数据库中存储纬度和经度值.我为Location对象创建了一个混合方法,
@hybrid_method
def great_circle_distance(self, other):
"""
Tries to calculate the great circle distance between the two locations
If it succeeds, it will return the great-circle distance
multiplied by 3959, which calculates the distance in miles.
If it cannot, it will return None.
"""
return math.acos( self.cos_rad_lat
* other.cos_rad_lat
* math.cos(self.rad_lng - other.rad_lng)
+ self.sin_rad_lat
* other.sin_rad_lat
) * 3959
Run Code Online (Sandbox Code Playgroud)
所有值都是cos_rad_lat和sin_rad_lat我预先计算的值,以优化计算.无论如何,当我运行以下查询时,
pq = Session.query(model.Location).filter(model.Location.great_circle_distance(loc) < 10)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,
line 809, in great_circle_distance
* math.cos(self.rad_lng - other.rad_lng) …Run Code Online (Sandbox Code Playgroud) 如何在sqlite数据库中以blob类型将数据库中的图像文件存储,以及如何从数据库中检索图像.
我有一个SQLite数据库,有大约40万个条目.要查询db我使用以下方法:
public double lookUpBigramFrequency(String bigram) throws SQLException {
SQLiteDatabase db = dbh.getReadableDatabase();
double frequency = 0;
bigram = bigram.toLowerCase();
String select = "SELECT frequency FROM bigrams WHERE bigram = '"
+ bigram + "'";
Cursor mCursor = db.rawQuery(select, null);
if (mCursor != null) {
if (mCursor.moveToFirst()) {
frequency = Double.parseDouble(mCursor.getString(0));
} else {
frequency = 0;
}
}
return frequency;
}
Run Code Online (Sandbox Code Playgroud)
但是检索单个条目并且查询很少需要大约0.5秒,它会建立并且方法执行10秒.怎么说出来?
我正在尝试将图像保存在核心数据中但是在我在模拟器中选择后,它不会显示在图像视图中?以下是代码示例:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (fugitive_.image != nil) {
self.fugitiveImage.image = [UIImage imageWithData:fugitive_.image];
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
fugitive.image = UIImagePNGRepresentation([info objectForKey:UIImagePickerControllerEditedImage]);
[self dismissModalViewControllerAnimated:YES];
[picker release];
}
Run Code Online (Sandbox Code Playgroud) sqlite ×10
database ×3
python ×3
android ×2
core-data ×2
ios ×1
ipad ×1
iphone ×1
mysql ×1
nhibernate ×1
nspredicate ×1
picker ×1
pylons ×1
sqlalchemy ×1
uiimageview ×1
xcode ×1