2011-10-27 6 views
1

私のSQLiteテーブルには、単純な0/1値のコサインSQLite doesn't has distinct boolean typeを格納するはずのカラム 'hasSubCountries'があります。SQLiteのブール値は常に0を返します

私はthis questionを見つけましたが、私の問題は解決しませんでした。私はオブジェクトに値を読み取ろう

hasSubCountries integer DEFAULT 0 

は1

そしてDBACCESSクラスにsubCountriesのカップルの値を変更している:私のデータベースで瞬間

私は列が持っている

ViewControllerをコードで
countryObj.hasSubCountries=(sqlite3_column_int(statement, 6) == 1); 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
Country* country = [[self.countries objectAtIndex:[indexPath section]] objectAtIndex:[indexPath row]]; 

if(country.hasSubCountries==1) 
    { 

    SelectedCountry *selCountry=[[SelectedCountry alloc]initWithNibName:@"SelectedCountry" bundle:nil]; 
    [selCountry setTitle:@"Country"]; 
    [selCountry setCountryID:country.countryID]; 
    [self.navigationController pushViewController:selCountry animated:YES]; 
    [selCountry release]; 
    } 
else 
    { 
    SubCountries *subCountries=[[SubCountries alloc]initWithNibName:@"SubCountries" bundle:nil]; 
    [subCountries setTitle:@"Sub"]; 
    [self.navigationController pushViewController:subCountries animated:YES]; 
    [subCountries release]; 
    } 

NSLog(@"%d ... %d",country.hasSubCountries,country.countryID); 
} 

NSLogは、とにかく私は0を得ていると言っています。そのため、もし 'if'が私を「Sub」にプッシュしているのです。 どこが間違っていたのですか?

問題のない国の名前とIDです。

enter image description here

+0

テーブル全体の列定義を追加できますか? – bryanmac

+0

もhasSubCountriesはBOOLですか? – bryanmac

+0

@bryanmac hasSubCountries整数DEFAULT 0 – NCFUSN

答えて

0

これは列インデックス7ではありませんか?

0 countryID
1 COUNTRYNAME
2 relativeToContinent
3 countryFlag
4 hasRegionalIssues
5 hasDifferentBankIssues
6 hasIssue
7 hasSubCountries

試行:

countryObj.hasSubCountries=(sqlite3_column_int(statement, 7) == 1); 

ない:

countryObj.hasSubCountries=(sqlite3_column_int(statement, 6) == 1); 
+0

私はそれを以前に試しました。助けにならない。 – NCFUSN

+0

です.2番目の引数はsqlite3_column_intへの列インデックスです。あなたのテーブル定義によると、hasSubCountriesは7つのインデックス列です。つまり、あなたがしている選択*。あなたのSQL文が明示的な列(共有していない)を持つ別のselect文である場合、それは7にはならないかもしれません。 – bryanmac

+0

const char * sqlCountries = sqlite3_mprintf( "countryID、countryName、countryFlag、hasRegionalIssues、hasDifferentBankIssues、hasIssue、hasSubCountries \ FROM countries \ where relativeToContinent =%i \ ORDER BY countryName ASC "、continentID); – NCFUSN

0

は、なぜあなたはあなたの思考を逆にしないでください:スクリーンショット

enter image description here

全テーブルの定義を参照してください?

countryObj.hasSubCountries=(sqlite3_column_int(statement, 6) != 0); 
+0

動作しません。私は同じ結果を得ています。0 – NCFUSN

+0

申し訳ありませんが、 私はばかだ(恥じて隠れている目です)。あなたの時間を無駄にして申し訳ありません。私は、SQLiteのselectクエリでこれらのフィールドを選択することを忘れています。すべてうまく動作します。 – NCFUSN

0

は、たぶん、それらのものは本当に文字列です。 sqlite3コマンドラインプログラムを使用してデータベースを開き、select hasSubCountries = 1 from countriesを実行してみてください。次にselect cast(hasSubCountries as integer) = 1 from countriesを試してください。

0

申し訳ありませんが、みんな、

それは馬鹿(恥ずかしいと隠して目)私です。あなたの時間を無駄にして申し訳ありません。私は、SQLiteのselectクエリでこれらのフィールドを選択することを忘れています。すべてうまく動作します。