/* -------------------------------------------------------------------
 *
 *	File: mSQL++.h
 *
 *	Date: 99/05/28
 *
 *	Author: Jürgen Schober, Point Design Software
 *
 *	Description: Definitions for the C++ wrapper for the msql.library.
 *			At least msql.library V5.0 is requiered.
 *			#undef _USE_ADAC_EXCEPTION_ to switch off
 *			Error-handling.
 *
 * ------------------------------------------------------------------- */

#ifndef ADAC_MSQL_PLUSPLUS_H
#define ADAC_MSQL_PLUSPLUS_H

#include <exec/types.h>
#include <proto/exec.h>
#include <proto/msql.h>
#include <libraries/msql.h>
#include <utility/tagitem.h>

// ADAC Includes

#define _USE_ADAC_EXCEPTION_

#include <ADAC/AdacException.h>


// if mSQL++ is used, the MsqlBase must not be defined in your
// source. It is also available to your code after the mSQL-constructor
// is called.

extern struct Library *MsqlBase;


class mSQL
{
protected:
	MsqlConnection *sql_Connect;
	BOOL sql_IsConnected;
public:
	// --- Construction/Destruction ---

	mSQL();
	~mSQL();

	// --- Additional Functions ---

	MsqlConnection* GetConnection() { return sql_Connect; }
	BOOL IsConnected() { return sql_IsConnected; }

	// --- Functions mentioned as "ARexx only" ---

	char* GetField(m_row row,int pos);
	int GetFieldInfo(m_field* fld);
	BOOL IsNotNull(m_field* fld);
	BOOL IsUnique(m_field* fld);

	// --- Msql.library V5.3 C++ Wrapper ---

	BOOL AddMHook(Hook* hook, TagList *tl = NULL);
	BOOL AddMHook(Hook* hook, ULONG varargs, ...);
	void RemMHook(Hook* hook);

	void AllocConnection(); // -> obsolent, see constructor
	void FreeConnection(); // -> obsolent, see destructor
	void Close();
	void Connect(char* host = NULL);
	int  CopyDB(char* dbFrom,char* dbTo);
	int  CreateDB(char* dbName);
	int  CopyDB(char* dbFrom,char* dbTo);
	int  DropDB(char *dbName);
	int  MoveDB(char* dbFrom,char* dbTo);
	int  SelectDB(char* dbName);
	void DataSeek(m_result* res,int pos);
	void FieldSeek(m_result* res,int pos);
	m_field* FetchField(m_result* res = NULL);
	m_row FetchRow(m_result *res = NULL);

	m_result* ListDBs();
	m_result* ListTables();
	m_result* ListFields(char *table);
	m_result* ListIndex(char* table,char* idx);
	int NumFields(m_result* res = NULL);
	int NumRows(m_result* res = NULL);
	int Query(char* query);
	m_result* StoreResult();
	void FreeResult(m_result* res = NULL);

	char* GetErrMsg();

	char* DateOffset(char* start, int day, int month, int year);
	time_t DateToUnixTime(char* date);
	int DiffDates(char* date1, char* date2);
	char* DiffTimes(char* time1, char* time2);
	char* SumTimes(char* time1,char* time2);
	time_t TimeToUnixTime(char* date);
	char* UnixTimeToDate(time_t time);
	char* UnixTimeToTime(time_t time);

	char* GetCharConf(char *y,char *z);
	int GetIntConf(char* y,char *z);
	int GetProtoInfo();
	char* GetHostInfo();
	m_seq* GetSequenceInfo(char *table);
	char* GetServerInfo();
	int	GetServerStats(char* buffer,ULONG size);

	int LoadConfigFile(char* filename);
	int ReloadAcls(); 
	int Shutdown();
};

#endif // ADAC_MSQL_PLUSPLUS_H
