Git Product home page Git Product logo

jkdbmodel's Issues

关于查询的问题

查询可以多元化一点么?或者说支持原生的sql语句。因为可能涉及多表或者多模型的查询删除等问题
例如项目中:

NSArray * personArray = [WHC_ModelSqlite query:[Person class] where:@"name != '吴海超'"];
我想查询的是person的car的name 等于 撼路者的
NSArray * personArray = [WHC_ModelSqlite query:[Person class] where:@"person.car.name = '撼路者'"];

就是 查询父类模型的继承属性的值 或 或者父类子类同时满足的条件,删除同理。。
希望可以支持复杂的查询。。。谢谢哈,个人意见仅供参考哈

关于查询数据的问题

只能支持 @" WHERE %@ = %d ",@"age",10 这种查询吗,不支持字符串匹配查询吗,我根据日期查询,查询不到数据。但是根据pk查询就可以。

请教个问题

在更新版本的时候问题:
app1.0版本用户模型中有10个属性,用数据库存储起来了
app2.0的时候新增了5个属性,也存起来了,会造成更新数据库模型错误,无法写入更新数据库
请问怎么解决呢?

if ([User isExistInTable]) {
if ([User findAll].count>0) {
user.pk = 1;
[user update];
}else{
[user save];
}
}

这个包想法不错,提几个意见

1.使用FMDatabaseQueue 他的结果是以block形式返回的 所以是异步的, 方法返回bool就没意义了。
2.不支持连表查询
3.不支持自定义的主键
4.有些数据类型的判断还不够全面
5.不支持索引、约束
5.表升级可以考虑封装

最后还是感谢原作者的思路,相当不错

请问使用JKDBModel出现如下问题

请问使用JKDBModel出现如下问题,我的每一个关键字都有值的
DB Query: INSERT INTO ZQFocusData(friends_id,friends_user_guid,nickname,logo,friends_status,friends_sex,friends_city,city,city_name,is_hufen,user_guid,isAddActivity,name,ios_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);
2016-03-10 17:41:14.287 SporterMan[47210:347830] Unknown error calling sqlite3_step (8: attempt to write a readonly database) eu

如何取得项目中已经存在的数据库文件

在JKDBHelper.m文件 --> + (NSString *)dbPathWithDirectoryName:(NSString *)directoryName 方法顶部加入如下代码

//修改取得代码 加入本地是否有需要替换的文件 如果利用本地项目文件 先对本地项目文件进行拷贝
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentFolderPath = [searchPaths objectAtIndex:0];

//往应用程序路径中添加数据库文件名称,把它们拼接起来, 这里用到了宏定义(目的是不易出错)
NSString *dbFilePath = [documentFolderPath stringByAppendingPathComponent:@"JKBD/jkdb.sqlite"];//#define DATABASE_FILE_NAME @"text.db"
//1. 创建NSFileManager对象  NSFileManager包含了文件属性的方法
NSFileManager *fm = [NSFileManager defaultManager];
//2. 通过 NSFileManager 对象 fm 来判断文件是否存在,存在 返回YES  不存在返回NO
BOOL isExist = [fm fileExistsAtPath:dbFilePath];

//- (BOOL)fileExistsAtPath:(NSString *)path;
//如果不存在 isExist = NO,拷贝工程里的数据库到Documents下
if (!isExist)
{

    //创建JKBD目录
    NSString *directryPath = [documentFolderPath stringByAppendingPathComponent:@"JKBD"];
    [fm createDirectoryAtPath:directryPath withIntermediateDirectories:YES attributes:nil error:nil];

    //拷贝数据库
    //获取工程里,数据库的路径,因为我们已在工程中添加了数据库文件,所以我们要从工程里获取路径
    NSString *backupDbPath = [[NSBundle mainBundle] pathForResource:@"jkdb" ofType:@"sqlite"];
    //这一步实现数据库的添加,
    // 通过NSFileManager 对象的复制属性,把工程中数据库的路径拼接到应用程序的路径上
    [fm copyItemAtPath:backupDbPath toPath:dbFilePath error:nil];
}

主键问题

大神,我获取最新插入的主键都为零 int a = [db lastInsertRowId];
这个方法,请问需要怎么解决

删除表操作

没有发现删除表操作,而且删除表的话,也打算用model去操作么?设计的字段更新蛮不错的,也不用考虑属性变了,数据库升级之类的。

NSCoding

为什么不实现NSCoding呢?这样当一个模型的属性是另外一个模型时,另外一个模型需要自己实现NSCoding,虽然可以自己实现,但是感觉不是很方便。

我往数据库存入了NSData数据类型,但是取出来的data却是空的

//
// ViewController.m
// FMDBTest
//
// Created by Felix on 2017/7/13.
// Copyright © 2017年 Felix. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"
#import "Dog.h"
#import <JKDBHelper.h>

@interface ViewController ()

@Property (nonatomic, strong) NSMutableArray *dataArray;

@EnD

@implementation ViewController

  • (NSMutableArray *)dataArray {
    if (!_dataArray) {
    _dataArray = [NSMutableArray array];
    }
    return _dataArray;
    }

  • (void)viewDidLoad {
    [super viewDidLoad];
    for (int i = 0; i < 20; i++) {
    Person *person = [Person new];
    person.age = i;
    NSMutableArray *temp = [NSMutableArray array];
    for (int j = 0; j < 10; j ++) {
    Dog *dog = [Dog new];
    dog.name = [NSString stringWithFormat:@"狗名%d", j];
    [temp addObject:dog];
    }
    person.dogs = temp.copy;
    [self.dataArray addObject:person];
    }

}

  • (IBAction)insetData:(id)sender {

    for (Person *person in self.dataArray) {
    person.dogsData = [NSKeyedArchiver archivedDataWithRootObject:person.dogs];
    }
    [Person clearTable];
    [Person saveObjects:self.dataArray];
    NSLog(@"%@", [JKDBHelper dbPath]);
    }

  • (IBAction)printfData:(id)sender {
    self.dataArray = [Person findAll].copy;
    for (Person *person in self.dataArray) {
    person.dogs = [NSKeyedUnarchiver unarchiveObjectWithData:person.dogsData];
    NSLog(@"%ld", (long)person.age);
    for (Dog *dog in person.dogs) {
    NSLog(@"%@", dog.name);

      }
    

    }
    }

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

@EnD

删除的方法有问题,删除肯定失败

/** 通过条件删除 (多参数)--2 */

  • (BOOL)deleteObjectsWithFormat:(NSString *)format, ...
    这个方法实现的时候用了local,加入pk>1000,formate会是1,000 ,由于小数点的存在导致删除失败。

关于PHAsset的保存

请问可以保存PHAsset吗?就是相册的PHAsset 可以保存 JKDBModel 的 一个属性里面吗?

关于FMDBQueue的问题

我读代码的时候有个问题. 这个写法似乎不合理

    NSMutableArray *users = [NSMutableArray array];
    [jkDB.dbQueue inDatabase:^(FMDatabase *db) {

            //. . .
            [users addObject:model];
            FMDBRelease(model);
        }
    }];
    
    return users;

比如像上面这种情况,我在queue里有很多个操作, 你如何能够确定.你在block外面写返回值. 而此时的返回能保证block里的获取的list已经执行完了? 这个return是立即返回的.

怎么取用NSData?

已有数据库,怎么取用NSData?应该怎么修改,可以取用NSdata?

关于更新和查询

我现在是遇到,假如有这样一组数据:传递回来的是一个数组,然后我可以保存,但是每次都会在之前数据后面叠加,以至于我没法查询到真实的数据。

个人对JKDB数组,float double 封装

radish322.zip

用JKDB也有段时间,感谢JOKER的开源对初学者有很大的帮助。这个是我基于JKDB封装了一层。项目时间太赶,做的是相当相当的粗糙,本人数据库方面的只是也很薄弱(数据渣)。希望JOKER大大和广大爱好者能给一些意见、
1、基于 getPropertys 方法,增加获取数组类,存储为blob类型
2、save的方法增加对数组,和可变数组的 归档,转为data
3、findAll 和 findByCriteria 增加 对数组,int类型,float double类型的判断。
-------3、22------
感谢zeqinjie的提醒,修改 isEqualToString 为 hasPrefix

关于创建表的时机的问题

你好,我们公司原产品使用的数据库就是:SQLitePersistentObject,现在因为SQLitePersistentObject很久不更新了,而且遇到多线程时会出现bug,所以新产品开发时选择了替换成JKDBModel,在使用JKDBModel过程中遇到一个问题,问题场景:客户端多个聊天窗口使用多张表存储,多张表继承同一个父类,使用runtime生成子表对应的类。现在的问题是,在使用运行时生成子表对应的类时,JKDBModel在
+initialize 方法中调用了创建表的方法,生成的表的名称是对应的父类的,不是对应子类的。我尝试将生成表的方法调用延迟到 -init 方法中,遇到一个位置错误,代码执行不通过。请问能否参照 SQLitePersistentObject 在操作对应表之前检查该表是否创建,若没有创建,先创建表,在执行对应的语句?

可以支持时间戳类型吗?

楼主,现在遇到一个问题,项目如果需要按时间戳去查找就麻烦了。添加时间戳字段具体要怎么操作,请版主赐教

swift工程下创建数据库异常

1,我的实体类继承了JKDBModel (为了截图方法删除了一些属性)
1
2.pch文件引入了JKDBModel和FMDB
2
3.从服务器获取到json并用字典生成对象,然后调用JKDBModel的save方法
3
4.但是后台就报错,说未知的数据库。XianZhi是我的工程名,为什么数据库未知?而且表名也是 工程名.实体名?该怎么解决?谢谢
4
5.插入数据当然也就报错了
5

不知道怎么使用

我想把所有的数据存在一个model中,不是我存一次他就创建一个model。
我不管储存多少次,我希望我最后查询的时候,数组里只有一个model。
不知道时候能实现呢?

查询条件带汉字

查询名字用汉字直接查查不出来
NSArray *array = [User findWithFormat:@" WHERE %@ = %@ ",@"name",@"麻子"];
应该怎么查?希望得到回复

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.