<< DbAffectedRowsNumber SciDb DbDisconnect >>

SciDb >> SciDb > DbConnect

DbConnect

connect to a database

Calling Sequence

dblink = DbConnect(provider,connectionString)
dblink = DbConnect(connectionStruct)

Parameters

provider

A string - name of the provider. Must have one of the following values : "MYSQL" - MySQL, "PSQL" - PostgreSQL (versions 7.3 and above), "OCI" - Oracle Call Interface Driver, "SQLITE" - SQLite version 3, "TDS" - Sybase Adaptive Server, "IBASE" - Borland InterBase, "ODBC" - Open Database Connectivity (ODBC) - Microsoft SQL Server and other ODBC-compliant databases, "DB2" - IBM DB2 (version 7.1 and above)

connectionString

Connection string, specific for provider, given as first argument at function call. See connection string formats for providers you use.

connectionStruct

A scilab struct, containing connection parameters. Must at least field 'provider', which has the same values as 'provider' - parameter. Other provider-independent values of struct: host, port, database, user, password. But format if this can also vary depending on provider. For Firebird(InterBase) provider and SQLite providers you must five the name of file of the database, for server-oriented databases you must specify the name of the database on server. Examples of connection struct for different providers:

  • For Firebird:

    connStr = struct ('provider', 'IBASE', 'database', 'D:\TEST.FDB', 'user', 'SYSDBA', 'password', 'masterkey')
    Here 'SYSDBA' and 'masterkey' are default credentials for Firebird provider.

  • For SQLite:

    connStr = struct ('provider', 'SQLITE', 'database', 'addressbook')
    This tries to connect to database addressbook in current directory. If SQLite database addressbook does not exist in the current directory, it will be created.

  • For PostgreSQL:

    connStr = struct ('provider', 'QPSQL', 'user', 'postgres', 'database', 'test')

  • For ODBC:

    • For local Access database

      connStr = struct('provider', 'ODBC', 'database', 'DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=Dbt.mdb')

    • For remote connection to MSSQL database:

      connStr = struct('provider', 'ODBC', 'database', 'DRIVER={SQL Native Client};SERVER=11.111.11.111,33301;DATABASE=remote_db', 'user', 'remote_user', 'password', 'remote_user_password')

    • For trusted connection to local MSSQL database:

      connStr = struct('provider', 'ODBC', 'database', 'DRIVER={SQL Native Client};SERVER=localhost;DATABASE=local_database; Trusted_Connection=yes')

  • For MySQL:

    connStr2 = struct ('provider', 'MYSQL', 'database', 'mytest', 'user', 'root', 'password', 'admin')

  • For OCI (Oracle):

    connStr2 = struct ('provider', 'OCI', 'database', 'XE', 'user', 'HR', 'password', 'hr')

There are also provider-specific parameters for each database provider.

  • For ODBC:

    • SQL_ATTR_ACCESS_MODE

    • SQL_ATTR_LOGIN_TIMEOUT

    • SQL_ATTR_CONNECTION_TIMEOUT

    • SQL_ATTR_CURRENT_CATALOG

    • SQL_ATTR_METADATA_ID

    • SQL_ATTR_PACKET_SIZE

    • SQL_ATTR_TRACEFILE

    • SQL_ATTR_TRACE

    • SQL_ATTR_CONNECTION_POOLING

    • SQL_ATTR_ODBC_VERSION

  • For MySQL:

    • CLIENT_COMPRESS

    • CLIENT_FOUND_ROWS

    • CLIENT_IGNORE_SPACE

    • CLIENT_SSL

    • CLIENT_ODBC

    • CLIENT_NO_SCHEMA

    • CLIENT_INTERACTIVE

    • UNIX_SOCKET

    • MYSQL_OPT_RECONNECT

  • For PostgreSQL:

    • connect_timeout

    • options

    • tty

    • requiressl

    • service

  • For DB2:

    • SQL_ATTR_ACCESS_MODE

    • SQL_ATTR_LOGIN_TIMEOUT

  • For OCI:

    • OCI_ATTR_PREFETCH_ROWS

    • OCI_ATTR_PREFETCH_MEMORY

  • For SQLite:

    • QSQLITE_BUSY_TIMEOUT

    • QSQLITE_OPEN_READONLY

    • QSQLITE_ENABLE_SHARED_CACHE

  • For Interbase:

    • ISC_DPB_LC_CTYPE

    • ISC_DPB_SQL_ROLE_NAME

Description

DbConnect(...) opens a connection to database and returns a pointer to connection object or results in an error if it is not possible to open a connection. Last succesfull connection becomes default.

Examples

// Opens a “PostgreSQL” connection with a connexion string
DbConnect("PSQL", ..
"Server=127.0.0.1;Database=myDataBase;User Id=myUsername;Password=myPassword;");
// Opens a “PostgreSQL” connection with a structure
connexionStruct          = struct();
connexionStruct.provider = "postgresql";
connexionStruct.database = "myDataBase";
connexionStruct.hostname = "127.0.0.1" ;
connexionStruct.use      = "myUsername";
connexionStruct.password = "myPassword";

DbConnect(connexionStruct);

See Also

Authors


Report an issue
<< DbAffectedRowsNumber SciDb DbDisconnect >>