/* 
   MySQLAdaptor.h

   Copyright (C) 2000 Free Software Foundation, Inc.

   Author: Stephen Peters <portnoy@portnoy.org>
	      based on the Postgres95 Adaptor written by 
	   Mircea Oancea <mircea@jupiter.elcom.pub.ro>
   Date: August 2000

   This file is part of the GNUstep Database Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; see the file COPYING.LIB.
   If not, write to the Free Software Foundation,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef __MySQLAdaptor_h__
#define __MySQLAdaptor_h__

#include <eoaccess/EOAdaptor.h>

/* Include MySQL Headers */

#undef Assert
#include <mysql/mysql.h>
#undef Assert

@class NSMutableArray;
@class NSMutableSet;

/* The following keys are meaningful in the connectionDictionary in a model:

    databaseServer or hostName - the name of the server 
	(default localhost)
    databaseName - the name of the database to use
    user - the MySQL login ID.
        (default current login name)
    password - the password to use for connecting.
        (default is blank pw, and is handled specially by MySQL)
    port - port for MySQL TCP/IP connection
	(default is standard MySQL port)
    options - the name of a group in the MySQL configuration file to use.
        This allows you to set up additional options such as timeout
	length, compression, init commands, default passwords, etc.
*/

@interface MySQLAdaptor : EOAdaptor
{
    NSMutableDictionary *typesByName;
    NSMutableDictionary *typesByCode;
    NSMutableArray *mysqlHandlePool;
    int mysqlHandlePoolLimit;

    struct {
	BOOL cacheMysqlHandle:1;
    } flags;
}

/* Reporting errors */
- (void)privateReportError:(MYSQL *)handle;

/* Getting the MySQL constant that represents a native type */
- (void)initTypeNames;

/* Configure the adaptor to share the MySQL connection handle or
   not. The default is not to share MySQL. */
- (void)setCacheMysqlHandle:(BOOL)flag;
- (BOOL)cacheMysqlHandle;
- (void)setMysqlHandlePoolLimit:(int)newLimit;
- (int)mysqlHandlePoolLimit;

- (NSString*)externalTypeNameForCode:(int) typeCode;
- (int)mysqlCodeForType:(NSString*)typeName;

/* Inherited methods */
- (Class)adaptorChannelClass;
- (BOOL)isValidQualifierType:(NSString*)typeName;

// Private methods

/* Obtaining and releasing a Mysql handle from pool */
- (MYSQL*)createMysqlHandle;
- (MYSQL*)newMysqlHandle;
- (void)releaseMysqlHandle:(MYSQL*)handle force:(BOOL)flag;

@end

#endif /* __MySQLAdaptor_h__ */
