File: SqlConnection.cpp

package info (click to toggle)
cvsnt 2.5.03.2382-3.3%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 32,288 kB
  • ctags: 24,567
  • sloc: ansic: 136,648; cpp: 102,037; sh: 42,846; asm: 3,495; makefile: 1,763; ada: 1,681; perl: 1,352; pascal: 1,089; cs: 1,008; yacc: 805; python: 453; xml: 263; sql: 210; lisp: 7
file content (136 lines) | stat: -rw-r--r-- 3,924 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
	CVSNT Generic API
    Copyright (C) 2004 Tony Hoyle and March-Hare Software Ltd

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License version 2.1 as published by the Free Software Foundation.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#include <config.h>
#include "lib/api_system.h"
#include "cvs_string.h"
#include "ServerIO.h"
#include "SqlConnection.h"
#include "LibraryAccess.h"

#ifdef _WIN32
#define STATIC_DB /* We can use late binding in Win32 to be more efficient */
#else
#undef STATIC_DB
#endif

extern "C" CSqlConnection *SQLite_Alloc();
extern "C" CSqlConnection *MySql_Alloc();
extern "C" CSqlConnection *Postgres_Alloc();
extern "C" CSqlConnection *Odbc_Alloc();
extern "C" CSqlConnection *Mssql_Alloc();
extern "C" CSqlConnection *Firebird_Alloc();
extern "C" CSqlConnection *Db2_Alloc();

CSqlConnection* CSqlConnection::Alloc(SqlConnectionType type, const char *dir)
{
#ifdef STATIC_DB
	switch(type)
	{
#ifdef HAVE_SQLITE
	case sqtSqlite:
		CServerIo::trace(3,"Connecting to SQLite");
		return SQLite_Alloc();
#endif
#ifdef HAVE_MYSQL
	case sqtMysql:
		CServerIo::trace(3,"Connecting to MySql");
		return MySql_Alloc();
#endif
#ifdef HAVE_POSTGRES
	case sqtPostgres:
		CServerIo::trace(3,"Connecting to Postgres");
		return Postgres_Alloc();
#endif
#ifdef HAVE_ODBC
	case sqtOdbc:
		CServerIo::trace(3,"Connecting to Odbc");
		return Odbc_Alloc();
#endif
#ifdef HAVE_MSSQL
	case sqtMssql:
		CServerIo::trace(3,"Connecting to MS-Sql");
		return Mssql_Alloc();
#endif
#ifdef HAVE_FIREBIRD
	case sqtFirebird:
		CServerIo::trace(3,"Connecting to Firebird");
		return Firebird_Alloc();
#endif
#ifdef HAVE_DB2
	case sqtDb2:
		CServerIo::trace(3,"Connecting to DB2");
		return Db2_Alloc();
#endif
	default:
		return NULL;
	}
#else /* not STATIC_DB */
	CLibraryAccess la;
	CSqlConnection* (*pNewSqlConnection)() = NULL;

	switch(type)
	{
	case sqtSqlite:
		CServerIo::trace(3,"Connecting to SQLite");
		if(!la.Load("sqlite"SHARED_LIBRARY_EXTENSION,dir))
			return false;
		pNewSqlConnection = (CSqlConnection*(*)())la.GetProc("SQLite_Alloc");
		break;
	case sqtMysql:
		CServerIo::trace(3,"Connecting to MySql");
		if(!la.Load("mysql"SHARED_LIBRARY_EXTENSION,dir))
			return false;
		pNewSqlConnection = (CSqlConnection*(*)())la.GetProc("MySql_Alloc");
		break;
	case sqtPostgres:
		CServerIo::trace(3,"Connecting to Postgres");
		if(!la.Load("postgres"SHARED_LIBRARY_EXTENSION,dir))
			return false;
		pNewSqlConnection = (CSqlConnection*(*)())la.GetProc("Postgres_Alloc");
		break;
	case sqtOdbc:
		CServerIo::trace(3,"Connecting to Odbc");
		if(!la.Load("odbc"SHARED_LIBRARY_EXTENSION,dir))
			return false;
		pNewSqlConnection = (CSqlConnection*(*)())la.GetProc("Odbc_Alloc");
		break;
	case sqtMssql:
		return NULL; // Win32 only (which is normally static)
	case sqtFirebird:
		CServerIo::trace(3,"Connecting to Firebird");
		if(!la.Load("firebird"SHARED_LIBRARY_EXTENSION,dir))
			return false;
		pNewSqlConnection = (CSqlConnection*(*)())la.GetProc("Firebird_Alloc");
		break;
	case sqtDb2:
		CServerIo::trace(3,"Connecting to DB2");
		if(!la.Load("db2"SHARED_LIBRARY_EXTENSION,dir))
			return false;
		pNewSqlConnection = (CSqlConnection*(*)())la.GetProc("Db2_Alloc");
		break;
	default:
		return NULL;
	}
	if(!pNewSqlConnection)
		return NULL;
	CSqlConnection *conn = pNewSqlConnection();
	la.Detach(); // Add a reference so the library never unloads
	return conn;
#endif
}