Declared in FMDatabaseAdditions.h
FMDatabaseAdditions.m

Overview

Category of additions for FMDatabase class.

See also

Tasks

Return results of SQL to variable

Schema related operations

Application identifier tasks

Instance Methods

applicationID

Retrieve application ID

- (uint32_t)applicationID

Return Value

The uint32_t numeric value of the application ID.

Declared In

FMDatabaseAdditions.h

applicationIDString

Retrieve application ID string

- (NSString *)applicationIDString

Return Value

The NSString value of the application ID.

Declared In

FMDatabaseAdditions.h

boolForQuery:

Return BOOL value for query

- (BOOL)boolForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

BOOL value.

Declared In

FMDatabaseAdditions.h

columnExists:columnName:

Test to see if particular column exists for particular table in database

- (BOOL)columnExists:(NSString *)tableName columnName:(NSString *)columnName

Parameters

tableName

The name of the table.

columnName

The name of the column.

Return Value

YES if column exists in table in question; NO otherwise.

Discussion

Warning: Deprecated - use columnExists:inTableWithName: instead.

Declared In

FMDatabaseAdditions.h

columnExists:inTableWithName:

Test to see if particular column exists for particular table in database

- (BOOL)columnExists:(NSString *)columnName inTableWithName:(NSString *)tableName

Parameters

columnName

The name of the column.

tableName

The name of the table.

Return Value

YES if column exists in table in question; NO otherwise.

Declared In

FMDatabaseAdditions.h

dataForQuery:

Return NSData value for query

- (NSData *)dataForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

NSData value.

Declared In

FMDatabaseAdditions.h

dateForQuery:

Return NSDate value for query

- (NSDate *)dateForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

NSDate value.

Declared In

FMDatabaseAdditions.h

doubleForQuery:

Return double value for query

- (double)doubleForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

double value.

Declared In

FMDatabaseAdditions.h

getSchema

The schema of the database.

- (FMResultSet *)getSchema

Return Value

FMResultSet of schema; nil on error.

Discussion

This will be the schema for the entire database. For each entity, each row of the result set will include the following fields:

  • type - The type of entity (e.g. table, index, view, or trigger)
  • name - The name of the object
  • tbl_name - The name of the table to which the object references
  • rootpage - The page number of the root b-tree page for tables and indices
  • sql - The SQL that created the entity

Declared In

FMDatabaseAdditions.h

getTableSchema:

The schema of the database.

- (FMResultSet *)getTableSchema:(NSString *)tableName

Parameters

tableName

The name of the table for whom the schema will be returned.

Return Value

FMResultSet of schema; nil on error.

Discussion

This will be the schema for a particular table as report by SQLite PRAGMA, for example:

PRAGMA table_info('employees')

This will report:

  • cid - The column ID number
  • name - The name of the column
  • type - The data type specified for the column
  • notnull - whether the field is defined as NOT NULL (i.e. values required)
  • dflt_value - The default value for the column
  • pk - Whether the field is part of the primary key of the table

See Also

Declared In

FMDatabaseAdditions.h

intForQuery:

Return int value for query

- (int)intForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

int value.

Declared In

FMDatabaseAdditions.h

longForQuery:

Return long value for query

- (long)longForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

long value.

Declared In

FMDatabaseAdditions.h

setApplicationID:

Set the application ID

- (void)setApplicationID:(uint32_t)appID

Parameters

appID

The uint32_t numeric value of the application ID.

See Also

Declared In

FMDatabaseAdditions.h

setApplicationIDString:

Set the application ID string

- (void)setApplicationIDString:(NSString *)string

Parameters

string

The NSString value of the application ID.

Declared In

FMDatabaseAdditions.h

stringForQuery:

Return NSString value for query

- (NSString *)stringForQuery:(NSString *)query, ...

Parameters

query

The SQL query to be performed.

...

A list of parameters that will be bound to the ? placeholders in the SQL query.

Return Value

NSString value.

Declared In

FMDatabaseAdditions.h

tableExists:

Does table exist in database?

- (BOOL)tableExists:(NSString *)tableName

Parameters

tableName

The name of the table being looked for.

Return Value

YES if table found; NO if not found.

Declared In

FMDatabaseAdditions.h

validateSQL:error:

Validate SQL statement

- (BOOL)validateSQL:(NSString *)sql error:(NSError **)error

Parameters

sql

The SQL statement being validated.

error

This is a pointer to a NSError object that will receive the autoreleased NSError object if there was any error. If this is nil, no NSError result will be returned.

Return Value

YES if validation succeeded without incident; NO otherwise.

Discussion

This validates SQL statement by performing sqlite3_prepare_v2, but not returning the results, but instead immediately calling sqlite3_finalize.

Declared In

FMDatabaseAdditions.h