thisチュートリアルを使用して、iOS用のアプリケーションをsqlite3データベースで作成しています。しかし、名前、姓、年齢の代わりに。私は名前と現在の日付を持っています。sqlite3はテキスト内のスペースを受け入れません(Objective-C)
私はNSDateを使って現在の日付を取得していますが、UITextFieldの代わりにUILabelに入れました。
ここでsaveを押すと、「構文エラー」が表示されます。私は現在の年を使ってみましたが、テーブルの列が "text"に設定されていても整数なので動作します。 「2017年2月16日」のようなスペーシングのある日付は、スペーシングがあるために動作していないようです。
16 Feb 2017の形式で保存します。
ありがとうございます!
それはのために働いて- (void)viewDidLoad {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterLongStyle];
//Get the date today.
NSString *dateToday = [formatter stringFromDate:[NSDate date]];
[super viewDidLoad];
// Do any additional setup after loading the view.
self.txtFirstname.delegate = self;
[_txtAge setText:dateToday];
- (IBAction)saveInfo:(id)sender {
// Prepare the query string.
// If the recordIDToEdit property has value other than -1, then create an update query. Otherwise create an insert query.
NSString *query;
if (self.recordIDToEdit == -1) {
query = [NSString stringWithFormat:@"insert into peopleInfo values(null, '%@', %@)", self.txtFirstname.text, self.txtDate.text];
}
else{
query = [NSString stringWithFormat:@"update peopleInfo set firstname='%@', date=%@ where peopleInfoID=%d", self.txtFirstname.text, self.txtDate.text, self.recordIDToEdit];
}
// Execute the query.
[self.dbManager executeQuery:query];
// If the query was successfully executed then pop the view controller.
if (self.dbManager.affectedRows != 0) {
NSLog(@"Query was executed successfully. Affected rows = %d", self.dbManager.affectedRows);
// Inform the delegate that the editing was finished.
[self.delegate editingInfoWasFinished];
// Pop the view controller.
[self.navigationController popViewControllerAnimated:YES];
}
else{
NSLog(@"Could not execute the query.");
}
}
テキストデータ型は、スペースを含むテキストを受け入れる必要があります。既存のバージョンアプリをデバイスやシミュレータから削除して、もう一度やり直してください。 – kb920
私はそれを試みたが、私はちょうど同じ取得: 2017-02-16 05:32:48.953091 "2月"の近くにSQLite3DBSample [627:104914]:構文エラー 2017-02-16 05:32:48.953236 SQLite3DBSample [627 :104914]クエリを実行できませんでした。 – Cuckoo
可能であれば、私に空のDBを送ってください。 – kb920