【问题标题】:How to write queries for DATE TIME data type in SQLITE iphone如何在 SQLITE iphone 中编写 DATE TIME 数据类型的查询
【发布时间】:2012-02-23 12:53:09
【问题描述】:
  • 在我的 sqlite 数据库中,我有一个 time 字段。
  • 到目前为止,我一直在使用类型“varChar”的时间。它运行良好
  • 但现在我需要将类型更改为 DateTime。
  • 如何更改以下查询以将 varchar 转换为日期和时间类型。 -在我的表列中是“时间”(DATETIME),“评论”(VARCHAR)

    • 在全选方法中。

    (NSMutableArray *)selectAllFromDB {

    time=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectAllStmt, 0)];

} __

-in insert method

-(BOOL)insertIntoDB:(NSMutableDictionary *)dict
{
        time=[dict objectForKey:@"time"];

        if(sqlite3_bind_text(insertStmt, 1, [time UTF8String], -1, SQLITE_TRANSIENT) != SQLITE_OK) 
        {
            return NO;
        }

}

如何针对日期数据类型修改这些查询

【问题讨论】:

    标签: iphone objective-c xcode sqlite


    【解决方案1】:

    试试这个:-

    -(BOOL)insertIntoDB:(NSMutableDictionary *)dict

    {
    
    time=[dict objectForKey:@"time"];
    

    if((sqlite3_bind_double(insert_statement, 1, [time timeIntervalSince1970])) != SQLITE_OK)

        {
            return NO;
        }
    
    }
    

    【讨论】:

    • 这里的“时间”不是 NSDate 类型的字符串。 NSDate *date = [formatter dateFromString: time];显示警告。“发送到 NSString 的不完整 ponter 类型”我的表有列“1.time:DATETIME”“2.cmets:VARCHAR”这里时间在我的表中是 DATETIME 类型
    • 当我在查询中使用 NSString 时,它存储空值
    • ate = [NSDate dateWithTimeIntervalSince1970:sqlite3_column_double(select_statement, 1)];.. 先生,我需要选择时间而不是时间间隔 sinc1971
    猜你喜欢
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多