FMDatabase(FMDatabaseAdditions) Category Reference

Declared in FMDatabaseAdditions.h

Overview

Category of additions for FMDatabase class.

See also

Return results of SQL to variable

– 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.

Discussion

Return int value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

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.

Discussion

Return long value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

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.

Discussion

Return BOOL value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

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.

Discussion

Return double value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

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.

Discussion

Return NSString value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

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.

Discussion

Return NSData value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

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.

Discussion

Return NSDate value for query

Note: To use this method from Swift, you must include FMDatabaseAdditionsVariadic.swift in your project.

Declared In

FMDatabaseAdditions.h

Schema related operations

– 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.

Discussion

Does table exist in database?

Declared In

FMDatabaseAdditions.h

– getSchema

The schema of the database.

- (FMResultSet *)getSchema

Return Value

FMResultSet of schema; nil on error.

Discussion

The schema of the database.

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

The schema of the database.

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

– 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.

Discussion

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

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

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

Warning: Deprecated - use columnExists:inTableWithName: instead.

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

Validate SQL statement

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

Declared In

FMDatabaseAdditions.h

Application identifier tasks

– applicationID

Retrieve application ID

- (uint32_t)applicationID

Return Value

The uint32_t numeric value of the application ID.

Discussion

Retrieve application ID

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.

Discussion

Set the application ID

See Also

Declared In

FMDatabaseAdditions.h

– applicationIDString

Retrieve application ID string

- (NSString *)applicationIDString

Return Value

The NSString value of the application ID.

Discussion

Retrieve application ID string

Declared In

FMDatabaseAdditions.h

– setApplicationIDString:

Set the application ID string

- (void)setApplicationIDString:(NSString *)string

Parameters

string

The NSString value of the application ID.

Discussion

Set the application ID string

Declared In

FMDatabaseAdditions.h

user version identifier tasks

– userVersion

Retrieve user version

- (uint32_t)userVersion

Return Value

The uint32_t numeric value of the user version.

Discussion

Retrieve user version

Declared In

FMDatabaseAdditions.h

– setUserVersion:

Set the user-version

- (void)setUserVersion:(uint32_t)version

Parameters

version

The uint32_t numeric value of the user version.

Discussion

Set the user-version

See Also

Declared In

FMDatabaseAdditions.h