Skip to content

DBCDatabase+Aliases

parfeon edited this page Feb 7, 2012 · 11 revisions

#DBCDatabase Aliases Category Reference
[SQLitews]:http://www.sqlite.org
[MAS]:http://www.apple.com/mac/app-store/
[DBCDatabaseCR]:https://github.com/parfeon/DBConnect/wiki/DBCDatabase
[DBCDatabaseInfoCR]:https://github.com/parfeon/DBConnect/wiki/DBCDatabaseInfo
[DBCDatabaseIndexInfoCR]:https://github.com/parfeon/DBConnect/wiki/DBCDatabaseIndexInfo
[DBCDatabaseTableColumnInfoCR]:https://github.com/parfeon/DBConnect/wiki/DBCDatabaseTableColumnInfo
[DBCDatabaseIndexedColumnInfoCR]:https://github.com/parfeon/DBConnect/wiki/DBCDatabaseIndexedColumnInfo
[DBCDatabaseBasicExample]:https://github.com/parfeon/DBConnect/wiki/DBCDatabase#basicExample
[DBCDatabase+Advanced]:https://github.com/parfeon/DBConnect/wiki/DBCDatabase+Advanced
[DBCErrorCR]:https://github.com/parfeon/DBConnect/wiki/DBCError
[DBCDatabaseEncodingUTF8c]:https://github.com/parfeon/DBConnect/wiki/Constants#DBCDatabaseEncodingUTF8 [ConstantsEncoding]:https://github.com/parfeon/DBConnect/wiki/Constants#DBCDatabaseEncoding Overview
This category contains some basic alias methods for common tasks, but was separated into category to keep autocomplete from showing you methods, which you probably will use or may not.
There are one more category for [DBCDatabase][DBCDatabaseCR] [Advanced][DBCDatabase+Advanced], this categories was created thematically on their purposes.
Aliases category adds mostly information aliases and few DML and DDL aliases methods, which can be evaluated to [sqlite][SQLitews] database.

##Tasks
###Database misc alias methods
- attachDatabase:databaseAttachName:error:
- detachDatabase:error:
- setDatabaseEncoding:error:
- databaseEncodingError:
- setUseCaseSensitiveLike:error
###DDL and DML alias methods
- dropTable:inDatabase:error:
- dropAllTablesInDatabase:error:
###Database information alias methods
- tablesCountError:
- tablesCountInDatabase:error:
- tablesListError:
- tablesListForDatabase:error:
- tableInformation:error:
- tableInformation:forDatabase:error:
- databasesListError:
- indicesList:forTable:error:
- indexedColumnsList:index:error:

##Instance methods

attachDatabase:databaseAttachName:error:

Method allows you to attach database from file or temporary database to main database w/o writing SQL statements.

- (BOOL)attachDatabase:(NSString*)dbFilePath databaseAttachName:(NSString*)dbAttachName error:(DBCError**)error

Parameters
dbFilePath
    [SQLite][SQLitews] database source can be specified as: path, file, ":memory:", "" or nil.
dbAttachName
    The name for attached database. You will use this name, when you need to query or update data in specified database.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
YES if database was successfully attached, otherwise NO.

Discussion
It is possible to use in-memory or temporary stored databases for attachment. If provided file path don't exists, than it will be created.
If main database was opened with read-only/read-write access, than all attached databases will have same access level.
All attached databases must have same encoding as main or you'll get an error.
After attachment, all access to attached database should be done via provided database name which was used when attached.
If [sqlite][SQLitews] database connection was opened in read-write access mode and database file for attachment placed in folder, where it can't be accessed for read-write access mode (application bundle for example) than you'' get an error.

How to use
In this example we will attach existing database to database, created in this [example][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR] into newly created database.

error = nil;
NSError *fmError = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
                    objectAtIndex:0];
if (![fileManager fileExistsAtPath:[docDir stringByAppendingPathComponent:@"test.sqlite"]]) {
    [fileManager copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"sqlite"] 
                          toPath:[docDir stringByAppendingPathComponent:@"test.sqlite"] error:&fmError];
}
[db attachDatabase:[docDir stringByAppendingPathComponent:@"test.sqlite"] databaseAttachName:@"aTest" 
             error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
}

See Also
- detachDatabase:error:
- setDatabaseEncoding:error:
- databaseEncodingError:
- setUseCaseSensitiveLike:error:

Top


detachDatabase:error:

Method allows you to detach attached earlier database w/o writing SQL statements.

- (BOOL)detachDatabase:(NSString*)attachedDatabaseName error:(DBCError**)error

Parameters
attachedDatabaseName
    The name which was used to attach desired database file to main database.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
YES if database was successfully detached, otherwise NO.

Discussion
This method simply detach attached earlier database w/o writing SQL statements. In case of temporary databases, all data will be lost. Don't try to issue detach method inside transaction or you'll get an error.

How to use
In this example, we will use results from example, shown earlier and detach aTest database:

error = nil;
[db detachDatabase:@"aTest" error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
}

See Also
- attachDatabase:databaseAttachName:error:
- setDatabaseEncoding:error:
- databaseEncodingError:
- setUseCaseSensitiveLike:error:

Top


setDatabaseEncoding:error:

Method allows you to change main database encoding w/o writing SQL statements.

- (BOOL)setDatabaseEncoding:(DBCDatabaseEncoding)encoding error:(DBCError**)error

Parameters
encoding
    New [sqlite][SQLitews] database encoding. [DBCDatabaseEncodingUTF8][DBCDatabaseEncodingUTF8c] preferred encoding.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
YES if database encoding was successfully changed, otherwise NO.

Discussion
Method allows you to change main database connection encoding w/o writing SQL statements. You can set encodings only for main database and only before database was initialized.
This method can't be called on database with read-only access.
Encoding controls how strings are encoded and stored in a database.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example I'll show how to set new encoding for database, we will set default [DBCDatabaseEncodingUTF8][DBCDatabaseEncodingUTF8c] encoding:

error = nil;
[db setDatabaseEncoding:DBCDatabaseEncodingUTF8 error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
}
error = nil;
DBCDatabaseEncoding encoding = [db databaseEncodingError:&error];

See Also
- attachDatabase:databaseAttachName:error:
- detachDatabase:error:
- databaseEncodingError:
- setUseCaseSensitiveLike:error:

Top


databaseEncodingError:

Method allows you to retrieve main database encoding w/o writing SQL statements.

- (DBCDatabaseEncoding)databaseEncodingError:(DBCError**)error

Parameters
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
Main [sqlite][SQLitews] database [encoding][ConstantsEncoding].

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example I'll show how to retrieve database encoding:

error = nil;
DBCDatabaseEncoding encoding = [db databaseEncodingError:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
}

See Also
- attachDatabase:databaseAttachName:error:
- detachDatabase:error:
- setDatabaseEncoding:error:
- setUseCaseSensitiveLike:error:

Top


setUseCaseSensitiveLike:error:

Method allows you to change case-sensitivity behavior for built-in LIKE expression w/o writing SQL statements.

- (BOOL)setUseCaseSensitiveLike:(BOOL)use error:(DBCError**)error

Parameters
use
    If set to YES than built-in LIKE will take into account string case, otherwise will ignore it.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
YES if case-sensitivity flag was successfully changed, otherwise NO.

Discussion
Method allows you to change built-in LIKE expression behavior with case-sensitivity when comparing strings w/o writing SQL statements.
This method can't be called on database with read-only access.
By default value set to NO and this means what comparator will ignore letter case.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example I'll show you how to set this flag and how it affect on queries with text matching:

error = nil;
// This select will return result
DBCDatabaseResult *result = [db executeQuery:@"SELECT * FROM test WHERE pTitle LIKE ?1"
                                       error:&error, @"cupertino", nil];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    NSLog(@"%@", result);
}

/* Output:
    Result for: SELECT * FROM test WHERE pTitle LIKE ?1;
    Query execution done in 0.000000s
    Found: 1 records
    Column names: pid | ptype | ptitle | loc_lat | loc_lon
    Result rows: (
        "1 | City | Cupertino | 37.3261 | -122.032"
    )
*/

error = nil;
[db setUseCaseSensitiveLike:YES error:&error];
// This select won't return any result because it can't math 'cupertino' to 'Cupertino'
DBCDatabaseResult *result = [db executeQuery:@"SELECT * FROM test WHERE pTitle LIKE ?1"
                                       error:&error, @"cupertino", nil];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    NSLog(@"%@", result);
}

/* Output:
    Result for: SELECT * FROM test WHERE pTitle LIKE ?1;
    Query execution done in 0.000000s
    Found: 0 records
    Column names: pid | ptype | ptitle | loc_lat | loc_lon
    Result rows: (
    )
*/

See Also
- attachDatabase:databaseAttachName:error:
- detachDatabase:error:
- setDatabaseEncoding:error:
- databaseEncodingError:

Top


dropTable:inDatabase:error:

Method allows you to drop table in specified database w/o writing SQL statements.

- (BOOL)dropTable:(NSString*)tableName inDatabase:(NSString*)databaseName error:(DBCError**)error

Parameters
tableName
    The name of the table, which should be dropped.
databaseName
    The name of database from which will be dropped table. If nil than main database will be used.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
YES if table was successfully dropped, otherwise NO.

Discussion
This method allows you to remove specific table from specified database w/o writing SQL statements. In case of [sqlite][SQLitews] after something was removed from database, database file won't reduce in size. So if you simply remove table with large number of records, database file will still the same size as before removing. This method solves this problem, but in some cases it may lead to ROWID reset. Cleanup can be executed only on main database, but if main is in memory database, than cleanup won't be done.
This method can't be called on database with read-only access.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
This is an example of how we can drop table in main database:

error = nil;
[db dropTable:@"test" inDatabase:nil error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
}

See Also
- dropAllTablesInDatabase:error:

Top


dropAllTablesInDatabase:error:

Method allows you to drop all tables in specified database w/o writing SQL statements.

- (BOOL)dropAllTablesInDatabase:(NSString*)databaseName error:(DBCError**)error

Parameters
databaseName
    The name of database from which will be dropped all tables. If nil than main database will be used.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
YES if all tables was successfully dropped, otherwise NO.

Discussion
This method allows you to drop all tables from specified database w/o writing SQL statements. In case of [sqlite][SQLitews] after something was removed from database, database file won't reduce in size. So if you simply remove all tables from database with large number of records, database file will still the same size as before removing. This method solves this problem, but in some cases it may lead to ROWID reset. Cleanup can be executed only on main database, but if main is in memory database, than cleanup won't be done.
This method can't be called on database with read-only access.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example we will drop all tables in main database:

error = nil;
[db dropAllTablesInDatabase:nil error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
}

See Also
- dropTable:inDatabase:error:

Top


tablesCountError:

Method allows you to retrieve number of tables in all attached databases w/o writing SQL statements.

- (int)tablesCountError:(DBCError**)error

Parameters
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
Number of tables in all attached databases.

Discussion
This method won't take into account [sqlite][SQLitews] service tables for indices and so on.

How to use
In this example, we will use results from one of the example, shown earlier and retrieve number of tables across all attached databases:

error = nil;
int tablesCount = [db tablesCountError:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    NSLog(@"Number of tables: %i", tablesCount);
}

See Also
- tablesCountInDatabase:error:
- tablesListError:
- tablesListForDatabase:error:

Top


tablesCountInDatabase:error:

Method allows you to retrieve number of tables in specified [sqlite][SQLitews] database w/o writing SQL statements.

- (int)tablesCountInDatabase:(NSString*)databaseName error:(DBCError**)error

Parameters
databaseName
    The name of database tables count of which you want to retrieve. If nil than main database will be used.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
Number of tables in specified [sqlite][SQLitews] database.

Discussion
This method won't take into account [sqlite][SQLitews] service tables for indices and so on.

How to use
In this example, we will use results from one of the example, shown earlier and retrieve number of tables in specified database:

error = nil;
int tablesCount = [db tablesCountInDatabase:@"aTest" error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    NSLog(@"Number of tables: %i", tablesCount);
}

See Also
- tablesCountError:
- tablesListError:
- tablesListForDatabase:error:

Top


tablesListError:

Method allows you to retrieve list of tables name in main database w/o writing SQL statements.

- (NSArray*)tablesListError:(DBCError**)error

Parameters
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of tables name in main database.

Discussion
This method won't take into account [sqlite][SQLitews] service tables for indices and so on.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example we will retrieve tables name for main database:

error = nil;
NSArray *tablesList = [db tablesListError:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    NSLog(@"Tables list: %@", tablesList);
}

See Also
- tablesCountError:
- tablesCountInDatabase:error:
- tablesListForDatabase:error:

Top


tablesListForDatabase:error:

Method allows you to retrieve list of tables name in specified database w/o writing SQL statements.

- (NSArray*)tablesListForDatabase:(NSString*)databaseName error:(DBCError**)error

Parameters
databaseName
    The name of database for which will be retrieved tables name list. If nil than main database will be used.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of tables name in specified database.

Discussion
This method won't take into account [sqlite][SQLitews] service tables for indices and so on.

How to use
In this example, we will use results from one of the example, shown earlier.
In this example we will retrieve tables name for specified database:

error = nil;
NSArray *tablesList = [db tablesListForDatabase:@"aTest" error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    NSLog(@"Tables list: %@", tablesList);
}

See Also
- tablesCountError:
- tablesCountInDatabase:error:
- tablesListError:

Top


tableInformation:error:

Method allows you to retrieve table structure (columns information) for main database w/o writing SQL statements.

- (NSArray*)tableInformation:(NSString*)tableName error:(DBCError**)error

Parameters
tableName
    The name of table in main database for which will be returned columns information.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of [DBCDatabaseTableColumnInfo][DBCDatabaseTableColumnInfoCR] for specified tableName in main database.

Discussion
Return list of [DBCDatabaseTableColumnInfo][DBCDatabaseTableColumnInfoCR] instances, which holds information about table column.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example I'll show how to retrieve table structure information from main database:

error = nil;
NSArray *tableColumnsList = [db tableInformation:@"test" error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    for(DBCDatabaseTableColumnInfo *colInfo in columnsList) NSLog(@"%@", colInfo);
}

/* Output:
    In sequence column number: 0
    Column name: pid
    Column data type: INTEGER
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: YES

    In sequence column number: 1
    Column name: pType
    Column data type: TEXT
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: NO

    In sequence column number: 2
    Column name: pTitle
    Column data type: TEXT
    Column is NOT NULL: NO
    Column default value: (null)
    Column is part of the primary key: NO

    In sequence column number: 3
    Column name: loc_lat
    Column data type: FLOAT
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: NO

    In sequence column number: 4
    Column name: loc_lon
    Column data type: FLOAT
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: NO
*/

See Also
- tableInformation:forDatabase:error:
- databasesListError:
- indicesList:forTable:error:
- indexedColumnsList:index:error:

Top


tableInformation:forDatabase:error:

Method allows you to retrieve table structure (columns information) for specified database w/o writing SQL statements.

- (NSArray*)tableInformation:(NSString*)tableName forDatabase:(NSString*)databaseName error:(DBCError**)error

Parameters
tableName
    The name of table in specified database for which will be returned columns information. databaseName
    The name of database in which specified table stored. If nil than main database will be used.
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of [DBCDatabaseTableColumnInfo][DBCDatabaseTableColumnInfoCR] for specific table in specified database.

Discussion
Return list of [DBCDatabaseTableColumnInfo][DBCDatabaseTableColumnInfoCR] instances, which holds information about table column.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example I'll show how to retrieve table structure information from specified database:

error = nil;
NSArray *tableColumnsList = [db tableInformation:@"test" forDatabase:nil error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    for(DBCDatabaseTableColumnInfo *colInfo in columnsList) NSLog(@"%@", colInfo);
}

/* Output:
    In sequence column number: 0
    Column name: pid
    Column data type: INTEGER
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: YES

    In sequence column number: 1
    Column name: pType
    Column data type: TEXT
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: NO

    In sequence column number: 2
    Column name: pTitle
    Column data type: TEXT
    Column is NOT NULL: NO
    Column default value: (null)
    Column is part of the primary key: NO

    In sequence column number: 3
    Column name: loc_lat
    Column data type: FLOAT
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: NO

    In sequence column number: 4
    Column name: loc_lon
    Column data type: FLOAT
    Column is NOT NULL: YES
    Column default value: (null)
    Column is part of the primary key: NO
*/

See Also
- tableInformation:error:
- databasesListError:
- indicesList:forTable:error:
- indexedColumnsList:index:error:

Top


databasesListError:

Method allows you to retrieve list of databases (main and attached) from current database connection w/o writing SQL statements.

- (NSArray*)databasesListError:(DBCError**)error

Parameters
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of [DBCDatabaseInfo][DBCDatabaseInfoCR] instances from current database connection.

Discussion
Return list of [DBCDatabaseInfo][DBCDatabaseInfoCR] instances, which holds information about databases. Databases like in-memory or temporary don't have file path in this objects.

How to use
In this example, we will use results from example, shown earlier and retrieve list of databases:

error = nil;
NSArray *databasesList = [db databasesListError:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    for(DBCDatabaseInfo *dbInfo in databasesList) NSLog(@"%@", dbInfo);
}

/* Output:
    Sequence number: 0
    Database name: main
    Database file path: 

    Sequence number: 2
    Database name: aTest
    Database file path: .../Documents/test.sqlite
*/

See Also
- tableInformation:error:
- tableInformation:forDatabase:error:
- indicesList:forTable:error:
- indexedColumnsList:index:error:

Top


indicesList:forTable:

Method allows you to retrieve list of indices for specific table in specified database w/o writing SQL statements.

- (NSArray*)indicesList:(NSString*)databaseName forTable:(NSString*)tableName error:(DBCError**)error

Parameters
databaseName
    The name of database in which specified table stored. If nil than main database will be used.
tableName
    The name of table in specified database for which will be returned list of [DBCDatabaseIndexInfo][DBCDatabaseIndexInfoCR].
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of [DBCDatabaseIndexInfo][DBCDatabaseIndexInfoCR] instances defined in specific table from specified database.

Discussion
Return list of [DBCDatabaseIndexInfo][DBCDatabaseIndexInfoCR] instances, which holds information about indices in specified table.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example we will retrieve list of indices for tables in specified database:

error = nil;
NSArray *indicesList = [db indicesList:nil forTable:@"test" error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    for(DBCDatabaseIndexInfo *indexInfo in indicesList) NSLog(@"%@", indexInfo);
}

/* Output:
    Sequence number: 0
    Index name: locationIndex
    Index is unique: YES
*/

See Also
- tableInformation:error:
- tableInformation:forDatabase:error:
- databasesListError:
- indexedColumnsList:index:error:

Top


indexedColumnsList:index:

Method allows you to retrieve index information (information of columns which is part of index) in specified database w/o writing SQL statements.

- (NSArray*)indexedColumnsList:(NSString*)databaseName index:(NSString*)indexName error:(DBCError**)error

Parameters
databaseName
    The name of database in which specified index defined. If nil than main database will be used.
indexName
    The name of index for which will be returned list of [DBCDatabaseIndexedColumnInfo][DBCDatabaseIndexedColumnInfoCR].
error
    If an error occurs, upon return contains an [DBCError][DBCErrorCR] object that describes the problem. Pass NULL if you do not want error information.

Return value
List of [DBCDatabaseIndexedColumnInfo][DBCDatabaseIndexedColumnInfoCR] instances.

Discussion
Return list of [DBCDatabaseIndexedColumnInfo][DBCDatabaseIndexedColumnInfoCR] instances, which holds information about columns which are the part of index.

How to use
In this example, we will use results from one of the [examples][DBCDatabaseBasicExample], shown earlier in [DBCDatabase Class Reference][DBCDatabaseCR].
In this example we will retrieve index information for specific table in specified database:

error = nil;
NSArray *indicedColumnsList = [db indexedColumnsList:nil index:@"locationIndex" error:&error];
if(error != nil){
    // In some rare cases an error may occur, just log it out to find out what gone wrong. Or you can set flag
       for DBCUseDebugLogger in DBCConfiguration.h, than DBConnect will log out all debug information.  
    NSLog(@"Occurred an error: %@", error);
} else {
    for(DBCDatabaseIndexedColumnInfo *indexColInfo in indicedColumnsList) NSLog(@"%@", indexColInfo);
}

/* Output:
    In index column number: 0
    In table column index: 3
    Column name: loc_lat

    In index column number: 1
    In table column index: 4
    Column name: loc_lon
*/

See Also
- tableInformation:error:
- tableInformation:forDatabase:error:
- databasesListError:
- indicesList:forTable:error:

Top

Clone this wiki locally