~ubuntu-branches/ubuntu/precise/myodbc/precise

« back to all changes in this revision

Viewing changes to driver/dll.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2004-02-15 14:59:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040215145929-wx1o3eobuhmmr2ft
Tags: 3.51.06-1
* New upstream release (closes: #149461).
* Add French debconf translations, thanks to Clément Stenac
  <zorglub@via.ecp.fr> (closes: #232839).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************  
 
2
 * Copyright (C) 1995-2002 MySQL AB, www.mysql.com                         *
 
3
 *                                                                         *
 
4
 * This program is free software; you can redistribute it and/or modify    *
 
5
 * it under the terms of the GNU General Public License as published by    *
 
6
 * the Free Software Foundation; either version 2 of the License, or       *
 
7
 * (at your option) any later version.                                     *
 
8
 *                                                                         *
 
9
 * This program is distributed in the hope that it will be useful,         *
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 
12
 * GNU General Public License for more details.                            *
 
13
 *                                                                         *
 
14
 * You should have received a copy of the GNU General Public License       *
 
15
 * along with this program; if not, write to the Free Software Foundation  *
 
16
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA           *
 
17
****************************************************************************/
 
18
 
 
19
/*************************************************************************** 
 
20
 * DLL.C                                                                   *
 
21
 *                                                                         *
 
22
 *  @description: For LIBMAIN processing                                   *
 
23
 *                                                                         *
 
24
 *  @author     : MySQL AB(monty@mysql.com, venu@mysql.com)                *
 
25
 *  @date       : 2001-Aug-15                                              *
 
26
 *  @product    : myodbc3                                                  *
 
27
 *                                                                         *
 
28
****************************************************************************/
 
29
 
 
30
#include "myodbc3.h"
 
31
#include <locale.h>
 
32
 
 
33
char *default_locale, *decimal_point, *thousands_sep;
 
34
uint decimal_point_length,thousands_sep_length;
 
35
static my_bool myodbc_inited=0;
 
36
 
 
37
/*
 
38
  @type    : myodbc3 internal
 
39
  @purpose : initializations
 
40
*/
 
41
 
 
42
void myodbc_init(void)
 
43
{
 
44
  if (myodbc_inited)
 
45
    return;
 
46
  myodbc_inited=1;
 
47
  my_init();
 
48
  {
 
49
    struct lconv *tmp;
 
50
    DBUG_ENTER("myodbc_init");
 
51
#ifdef LOG_ALL
 
52
#ifdef _UNIX_
 
53
    DBUG_PUSH("d:t:S:O,/tmp/myodbc.log");
 
54
#else
 
55
    DBUG_PUSH("d:t:S:O,c::\\myodbc.log");
 
56
#endif
 
57
#else
 
58
    if (getenv("MYODBC_LOG") != NULL)
 
59
      DBUG_PUSH(getenv("MYODBC_LOG"));
 
60
#endif
 
61
    init_getfunctions();
 
62
    default_locale=my_strdup(setlocale(LC_NUMERIC,NullS),MYF(0));
 
63
    setlocale(LC_NUMERIC,"");
 
64
    tmp=localeconv();
 
65
    decimal_point=my_strdup(tmp->decimal_point,MYF(0));
 
66
    decimal_point_length=strlen(decimal_point);
 
67
    thousands_sep=my_strdup(tmp->thousands_sep,MYF(0));
 
68
    thousands_sep_length=strlen(thousands_sep);
 
69
    setlocale(LC_NUMERIC,default_locale);
 
70
    DBUG_VOID_RETURN;
 
71
  }
 
72
}
 
73
 
 
74
/*
 
75
  @type    : myodbc3 internal
 
76
  @purpose : clean all resources while unloading..
 
77
*/
 
78
 
 
79
void myodbc_end()
 
80
{
 
81
 if (myodbc_inited)
 
82
 {
 
83
   myodbc_inited=0;
 
84
   my_free(decimal_point,MYF(0));
 
85
   my_free(default_locale,MYF(0));
 
86
   my_free(thousands_sep,MYF(0));
 
87
#ifdef NOT_YET_USED
 
88
   mysql_server_end();
 
89
#endif
 
90
   my_end(0);
 
91
 }
 
92
}
 
93
 
 
94
/*
 
95
  @type    : myodbc3 internal
 
96
  @purpose : main entry point
 
97
*/
 
98
 
 
99
#ifdef _WIN32
 
100
static int inited=0,threads=0;
 
101
HINSTANCE NEAR s_hModule; /* Saved module handle */
 
102
int APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called,
 
103
         LPVOID lpReserved)
 
104
{
 
105
  switch (ul_reason_being_called) {
 
106
  case DLL_PROCESS_ATTACH:  /* case of libentry call in win 3.x */
 
107
  if (!inited++)
 
108
  {
 
109
    s_hModule=hInst;
 
110
    myodbc_init();
 
111
  }
 
112
  break;
 
113
  case DLL_THREAD_ATTACH:
 
114
    threads++;
 
115
#ifdef THREAD
 
116
    my_thread_init();
 
117
#endif
 
118
    break;
 
119
  case DLL_PROCESS_DETACH:  /* case of wep call in win 3.x */
 
120
    if (!--inited)
 
121
      myodbc_end();
 
122
    break;
 
123
  case DLL_THREAD_DETACH:
 
124
#ifdef THREAD
 
125
    if (threads && --threads)
 
126
      my_thread_end();    /* Last will be freed in my_end() */
 
127
#else
 
128
    --threads;
 
129
#endif
 
130
    break;
 
131
  default:
 
132
    break;
 
133
  } /* switch */
 
134
 
 
135
  return TRUE;
 
136
 
 
137
  UNREFERENCED_PARAMETER(lpReserved);
 
138
} /* LibMain */
 
139
 
 
140
/*
 
141
  @type    : myodbc3 internal
 
142
  @purpose : entry point for the DLL
 
143
*/
 
144
 
 
145
int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,
 
146
                      LPVOID lpReserved)
 
147
{
 
148
  return LibMain(hInst,ul_reason_being_called,lpReserved);
 
149
}
 
150
 
 
151
#elif defined(__WIN__)
 
152
 
 
153
/***************************************************************************
 
154
  This routine is called by LIBSTART.ASM at module load time.  All it
 
155
  does in this sample is remember the DLL module handle.  The module
 
156
  handle is needed if you want to do things like load stuff from the
 
157
  resource file (for instance string resources).
 
158
***************************************************************************/
 
159
 
 
160
int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize,
 
161
             SQLCHAR FAR *lszCmdLine)
 
162
{
 
163
  s_hModule = hModule;
 
164
  myodbc_init();
 
165
  return TRUE;
 
166
}
 
167
 
 
168
#endif /* __WIN__ */
 
169
 
 
170
#ifdef _WIN32
 
171
void __declspec( dllexport) FAR PASCAL LoadByOrdinal(void);
 
172
/* Entry point to cause DM to load using ordinals */
 
173
void __declspec( dllexport) FAR PASCAL LoadByOrdinal(void)
 
174
{}
 
175
#endif