Mimer SQL Documentation PREV NEXT

Mimer Developer Site

www.mimer.com/developer


3.1 Main Program


The main program looks as follows:

#include <windows.h>
#include <odbcinst.h>
#include <stdio.h>
#include <stdlib.h>
#include <sqlext.h>
void main()
{
			I_SetupLicense();
			I_DefineDatabase();
			I_CreateSystemDatabanks();
			I_StartupDatabaseServer();
			I_CreateApplicationObjects();
			exit(0);
} 

3.1.1 I_SetupLicense

The first example subroutine adds a Mimer SQL license key. Note that different machines usually have different installation numbers and license keys. This routine is only needed when an application is distributed with a license key.

void I_SetupLicense()
{
			BOOL rc; 
			rc = 		SQLConfigDataSource(NULL, 					ODBC_ADD_SYS_DSN,
					"MIMER",
					"InstallationNo=12345\0"
					"LicenseKey=23CB23B7C8D33E2F206A23CDEF67\0"
					"DESCRIPTION=This is my license key\0\0");
			if	(!rc) {
				 I_InstError("Error adding Mimer SQL license:");
			}
} 

3.1.2 I_DefineDatabase

This routine defines the ODBC data source and the Mimer SQL database parameters:

void I_DefineDatabase()
{
			BOOL rc;
			rc =		SQLConfigDataSource(NULL, 					ODBC_ADD_SYS_DSN,
					"MIMER",
					"DSN=MyODBC\0DATABASE=MyMIMER\0"
					"DIRECTORY=c:\\MyDirectory\0"
					"USERS=200\0"
					"DESCRIPTION=This is my sample database\0\0");
			if	(!rc) {
		 		 I_InstError("Error creating database definition:");
			}
} 

3.1.3 I_CreateSystemDatabanks

This routine starts a process that runs the Mimer SQL system databank generation program in silent mode.

void I_CreateSystemDatabanks()
{
			BOOL rc;
			rc =		SQLConfigDataSource(NULL, ODBC_CONFIG_SYS_DSN,
					"MIMER",
					"DATABASE=MyMimer\0"
					"SDBGEN=-pSYSPSW MyMimer\0\0");
			if	(!rc) {
				 I_InstError("Error creating System Databanks:");
			}
} 

3.1.4 I_StartupDatabaseServer

The following code starts the database server:

void I_StartupDatabaseServer()
{
			BOOL rc;
			rc =		SQLConfigDataSource(NULL, ODBC_CONFIG_SYS_DSN,
					"MIMER",
					"DATABASE=MyMimer\0"
					"DbServer=START\0\0");
			if	(!rc) {
				 I_InstError("Error starting database server:");
			}
} 

3.1.5 I_CreateApplicationObjects

This routine sets up the Mimer SQL database environment needed by the application. For clarity, error handling has been left out of this routine.

void I_CreateApplicationObjects()
{
			RETCODE rc;
			HENV hEnv;
			HDBC hCon;
			HSTMT hStmt;
			rc =		SQLAllocEnv(&hEnv);
			rc =		SQLAllocConnect(hEnv, &hCon);
			rc =		SQLConnect(hCon,
					"MyODBC", SQL_NTS,
					"SYSADM", SQL_NTS,
					"SYSPSW", SQL_NTS);
			rc =	 SQLAllocStmt(hCon, &hStmt);
/*
 *  Add application specific object creation here
 */
			rc =		SQLExecDirect(hStmt, 
					"CREATE IDENT ...", SQL_NTS);
			.
			.
			. 
/*
 *  Done, logout from database system
 */
		 	rc = SQLDisconnect(hCon);
		 	rc = SQLFreeEnv(hEnv);
} 

To make the sample complete, you should add code for creating the Mimer SQL objects such as databanks, users, tables, and views needed to run the application.

3.1.6 I_InstError

An example of the error handling used by the other examples follows:

void I_InstError(char *pszOperation)
{
			RETCODE rc;
			WORD iError, cbErrorMsg;
			DWORD fErrorCode;
			char szErrorMsg[1000];
			printf("%s\n", pszOperation);
			for (iError = 1; iError <= 8; iError++) {
				rc =		SQLInstallerError(iError,
						&fErrorCode, 
						szErrorMsg,
						sizeof(szErrorMsg),
						&cbErrorMsg);
				if	(rc == SQL_NO_DATA_FOUND ||
					 rc == SQL_ERROR) {
					 break;
				}
				printf("%d: Error code = %d, Message = %s\n",
						 iError,
						 fErrorCode,
						 szErrorMsg);
			}
} 

The routine SQLInstallerError is further described in SQLInstallerError and also in the Microsoft ODBC documentation.



Upright Database Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40
dbtechnology@upright.se
Mimer SQL Documentation PREV NEXT