Switch to: V10V9V8V7V6V5

VDatabaseController

Inherits from NSObjectController
Represents object Vdatabase
Declared in V4CC_VDatabaseController.h

Overview

VDatabaseController - manages the VDatabase class and provides access to a Valentina database, which can be local or remote. You should to connect VDatabaseController to VLocalConnection or to VClientConnection to define that.

The rules - how to specify the path to the database:

If you use VDdatabaseController, to get access to the local database, you can specify path to the database by several ways:

  • Absolute path: Database Path should begin with /.

Example:

/home/mydatabases 
  • When database located at the same folder where the application: Database Path should be empty.
  • When database located in the application package: Database Path should begin with @.

Example:

@/Contents/mydatabases 
  • When database located in the folder a few levels above: Database Path should begin with /../. For each higher level - type /../

Example:

/../../Contents/mydatabases 

Tasks

Please familiarise with tasks of all controllers before programming your application. Some task may be invoked and executed by high-level's objects. And you should not invoke them directly.

Construction Methods

Init Database Controller

Properties

Select Method

Class Methods

initClientDatabase:

- (id)initClientDatabase:(NSString*)inDatabaseName;

If you use database from Valentina's Server, use this method to set the database name.

initLocalDatabase:name:path:

- (id)initLocalDatabase:(EVStorageType)inStorageType name:(NSString*)inDatabaseName path:(NSString*)inDatabasePath;

If you use local database, use this method to set initial parameters:

dealloc

Releases VDatabaseController properties

- (void)dealloc;

initDatabaseController

Initializes a VDatabase and connection.

- (void)initDatabaseController;

Discussion
This method works at two steps:

  1. initializes own connection controller;
  2. initialize VDatabase object.

To initialize connection controller this method invokes -initConnection method for Local or Client connection.

database

Accessors for VDatabase object, of the VDatabaseController.

- (VDatabase*)database;
- (void)setDatabase:(VDatabase*)inDatabase;

connectionController

Accessors for connectionController object, of the VDatabaseController.

- (id)connectionController;
- (void)setConnectionController:(id)inConnectionController;

Discussion
You can use this method independently of the connection type.

Return Value
If you use local connection, the return type will be VLcoalConnection. If you use client connection, the return type will be VClientConnection.

databaseName

Accessors for databaseName property.

- (NSString*)databaseName;
- (void)setDatabaseName:(NSString*)inDatabaseName;

databasePath

Accessors for databasePath property.

- (NSString*)databasePath;
- (void)setDatabasePath:(NSString*)inDatabaseName;

Input parameter
inDatabaseName - this is string, which represents URI of the database.

Example

  • ”/”;
  • ”/Documents/MyDocuments/databases/”.

Discussion
If you get database from the server, using client connection, you should not use this method.

currentInitType

Accessors for currentInitType property.

- (EVDatabaseLocation)currentInitType;
- (void)setCurrentInitType:(int)inInitType;

Discussion
There are two types of sources for database - database on Server, database on local machine. It is represented in the enum:

typedef enum
{
	dbClient = 0,
	dbLocal
} EVDatabaseLocation;

Using accessor method, you can define current connection type.

currentStorageType

Accessors for currentStorageType property.

- (EVStorageType)currentStorageType;
- (void)setCurrentStorageType:(int)inStorageType;

Use this method to set, or to define database Storage Type.

makeSelectWithQuery:cursorLocation:lockType:direction:binds:

Executes SQL SELECT command from own VDatabase object.

- (VCursor*) makeSelectWithQuery:(NSString*)inQuery 
	          cursorLocation:(EVCursorLocation)inLocation  
		        lockType:(EVLockType)inLockType
		       direction:(EVCursorDirection)inDirection 
			   binds:(NSArray*)inBinds;

Return Value
Returns VCursor object.

Discussion
This method used by VCursorController for initializing own VCursor object. If you use VCursorController you should not use this method. But, as you see you can get the cursor directly from VDatabaseController using this method.

Code Example

- (VCursor*)getCursor
{
     VClientConnection* connection;
     connection = [[VClientConnection alloc] initWithHost:@"localhost" 
					         userName:@"sa"
					         password:@"sa"];		
 
     VDatabaseController* database;
     database = [[VDatabaseController alloc] initClientDatabaseName:@"db1.vdb"];
 
     [database initDatabaseController];
 
     return [database makeSelectWithQuery:@"SELECT * FROM Person"
			   cursorLocation:kServerSide  
			         lockType:kReadOnly
			        direction:kRandom 
			            binds:nil];
}