[gnome-db] sybase provider



hello all,

i've had some time to burn this week, so i've been hacking the sybase
provider for the gnome 2 version of libgda.

attached is a diff to enable building of the sybase provider.  I've also
attached some new files that need to be added to CVS.  

I haven't been able to test it just yet, because the gda-test program
can't seem to find my DSN entries i've defined with the gnome 1.4
version of the gnome-db front end.

Would it be ok to use the default provider as the model for the sybase
provider, or should I wait for the MySQL version to be finished?

happy hacking everyone.

mike



Index: configure.in
===================================================================
RCS file: /cvs/gnome/libgda/configure.in,v
retrieving revision 1.119
diff -u -u -r1.119 configure.in
--- configure.in	2001/11/22 23:59:46	1.119
+++ configure.in	2001/12/04 22:21:38
@@ -463,6 +463,7 @@
 providers/default/Makefile
 providers/default/sqlite/Makefile
 providers/mysql/Makefile
+providers/sybase/Makefile
 tools/Makefile
 tools/gda-buildserver
 tools/gda-buildclient
bin_PROGRAMS = gda-sybase-srv

INCLUDES = \
	-I. \
	$(LIBGDA_CFLAGS) \
	$(SYBASE_CFLAGS)

gda_sybase_srv_SOURCES = \
	gda-sybase-provider.c \
	gda-sybase-provider.h \
	gda-sybase.h \
	gda-sybase-error.c \
	main.c

gda_sybase_srv_LDADD = \
	$(LIBGDA_LIBS) \
	$(top_builddir)/libgda/libgda-2.la \
	$(SYBASE_LIBS)

serverdir=$(libdir)/bonobo/servers

server_in_files = GNOME_Database_Provider_Sybase.server.in
server_DATA = $(server_in_files:.server.in=.server)

@INTLTOOL_SERVER_RULE@

EXTRA_DIST=$(server_in_files) $(server_DATA)
<oaf_info>

<oaf_server iid="OAFIID:GNOME_Database_Sybase_ComponentFactory"
            type="exe"
            location="gda-sybase-srv">
	<oaf_attribute name="repo_ids" type="stringv">
		<item value="IDL:GNOME/GenericFactory:1.0"/>
	</oaf_attribute>
	<oaf_attribute name="name" type="string" _value="Sybase component factory"/>
</oaf_server>

<oaf_server iid="OAFIID:GNOME_Database_Sybase_Provider"
	    type="factory"
	    location="OAFIID:GNOME_Database_Sybase_ComponentFactory">
	<oaf_attribute name="repo_ids" type="stringv">
		<item value="IDL:GNOME/Database/Provider:1.0"/>
	</oaf_attribute>
	<oaf_attribute name="description" type="string"
	               _value="GDA Datasource Access for Sybase"/>
	<oaf_attribute name="gda_params" type="stringv">
		<item value="HOST"/>
		<item value="USERNAME"/>
	 <item value="APPNAME"/>
		<item value="PASSWORD"/>
		<item value="DATABASE"/>
	</oaf_attribute>
</oaf_server>

</oaf_info>
/* GDA sybase provider
 * Copyright (C) 1998-2001 The Free Software Foundation
 *
 * AUTHORS:
 *      mike wingert <wingert 3 postbox acs ohio-state edu>
	*      based on the MySQL provider by
 *         Michael Lausch <michael lausch at>
 *	        Rodrigo Moya <rodrigo gnome-db org>
 *         Vivien Malerba <malerba gnome-db org>
 * 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, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gda-sybase.h"

GdaError *
gda_sybase_make_error (sybase_connection *sconn)
{
	GdaError *error;

	error = gda_error_new ();
	if (sconn->err.error_msg != NULL) 
			{
					gda_error_set_description (error, sconn->err.error_msg);
/*  					gda_error_set_number (error, mysql_errno (handle)); */
			}
	else 
			{
					gda_error_set_description (error, "NO DESCRIPTION");
					gda_error_set_number (error, -1);
			}
	gda_error_set_source (error, "gda-sybase");
	gda_error_set_sqlstate (error, "Not available");

	return error;
}

gboolean
sybase_check_messages(GdaServerConnection *cnc)
{
		CS_RETCODE ret;
		CS_INT msg_count;
		gboolean clientmsg_retval = FALSE;
		gboolean servermsg_retval = FALSE;
		gboolean cmsg_retval = FALSE;
		gboolean msgcheck = FALSE;
		sybase_connection *sconn;

		/* with sybase, after every call to the client library */
		/* we check the messages */
		sconn = g_object_get_data(G_OBJECT(cnc),OBJECT_DATA_SYBASE_HANDLE);

		if (sconn)
				{
/*  						 do we have a valid connection structure?  */
						if (sconn->connection)
								{     	
/*  										 see if there is any messages  */
										ret = ct_diag (sconn->connection, 
																									CS_STATUS, 
																									CS_ALLMSG_TYPE,
																									CS_UNUSED, 
																									&msg_count); 										
										if (ret != CS_SUCCEED)
												{
														/* this is bad, we can't get a message count  */
														/* FIXME - i'll worry about this later 					 */
														return TRUE;	
												}
										if (msg_count < 1)
												{
														/* woo hoo! no messages, so return FALSE */
														return FALSE;						
												}
/*  										if any of the retval = TRUE, there was an error  */
										clientmsg_retval = sybase_check_clientmsg(cnc);
										servermsg_retval = sybase_check_servermsg(cnc);
							}
					if (sconn->context)
							{
									cmsg_retval = sybase_check_cmsg(cnc);										
							}
			}	
	if ((cmsg_retval) || (clientmsg_retval) || (servermsg_retval))
			{
					return TRUE;
			}
	else
			{
					return FALSE;
			}
		return TRUE;

}

gboolean 
sybase_check_clientmsg(GdaServerConnection *cnc)
{
		CS_RETCODE ret = CS_SUCCEED;
		CS_INT msgcnt = 0;
		CS_INT msgcur = 0;
		GdaError *err;
		gchar *message;
		gboolean error_occured = FALSE;
		CS_CLIENTMSG msg;
		sybase_connection *sconn;

		sconn = g_object_get_data(G_OBJECT(cnc),OBJECT_DATA_SYBASE_HANDLE);

		if (sconn)
				{
						if (sconn->connection)
								{
										ret = ct_diag (sconn->connection, 
																									CS_STATUS, 
																									CS_CLIENTMSG_TYPE, 
																									CS_UNUSED,
																									&msgcnt);												
										if (ret != CS_SUCCEED)
												{
														sconn->err.error_msg = g_new(gchar,201);
														g_snprintf(message,
																									200,
																									"%s",
																									_("ct_diag 1 failed in sybase_check_clientmsg"));
														err = gda_sybase_make_error(sconn);
														gda_server_connection_add_error(cnc,err);
														g_free((gpointer)sconn->err.error_msg);
														return TRUE;
												}
										if (!msgcnt)
												return FALSE;
										while (msgcur < msgcnt)
												{
														msgcur++;						
														ret = ct_diag (sconn->connection, 
																													CS_GET, 
																													CS_CLIENTMSG_TYPE, 
																													msgcur,
																													&msg);	
														if (ret != CS_SUCCEED)
																{
																		sconn->err.error_msg = g_new(gchar,201);
																		g_snprintf(message,
																													200,
																													"%s",
																													_("ct_diag 2 failed in sybase_check_clientmsg"));
																		err = gda_sybase_make_error(sconn);
																		gda_server_connection_add_error(cnc,err);
																		g_free((gpointer)sconn->err.error_msg);
																		error_occured = TRUE;
																}
														if (msg.severity != CS_SV_INFORM)
																{
																		sconn->err.error_msg = sprintf_clientmsg(_("Client Message: "),
																																																											&msg);
																		err = gda_sybase_make_error(sconn);
																		gda_server_connection_add_error(cnc,err);
																		g_free((gpointer)sconn->err.error_msg);																		
																		error_occured = TRUE;
																}
														else
																{
																		/* this will just print to a debug file for now */
																		sconn->err.error_msg = 
																				sprintf_clientmsg(_("Informational Client  Message: "),
																																																											&msg);
																		sybase_debug_msg(sconn->err.error_msg);
																		g_free((gpointer)sconn->err.error_msg);	
																}
														/* check if we have any new messages to worry about */
														if (msgcur == msgcnt) 
																{
																		ret = ct_diag (sconn->connection, 
																																	CS_STATUS,
																																	CS_CLIENTMSG_TYPE, 
																																	CS_UNUSED, 
																																	&msgcnt);
																		if (ret != CS_SUCCEED) 
																				{
																						sconn->err.error_msg = g_new(gchar,201);
																						g_snprintf(message,
																																	200,
																																	"%s",
																																	_("ct_diag 2 failed in sybase_check_clientmsg"));
																						err = gda_sybase_make_error(sconn);
																						gda_server_connection_add_error(cnc,err);
																						g_free((gpointer)sconn->err.error_msg);
																						error_occured = TRUE; 			
																				} /* if ret != CS_SUCCEED */
																} /* if msgcur == msgcnt */
												} /* while msgcur < msgcnt */ 
								} /* if sconn->connection */	
				} /* if sconn */
		return error_occured;	
}

gboolean 
sybase_check_servermsg(GdaServerConnection *cnc)
{
		CS_RETCODE ret = CS_SUCCEED;
		CS_INT msgcnt = 0;
		CS_INT msgcur = 0;
		GdaError *err;
		gchar *message;
		gboolean error_occured = FALSE;
		CS_SERVERMSG msg;
		sybase_connection *sconn;

		sconn = g_object_get_data(G_OBJECT(cnc),OBJECT_DATA_SYBASE_HANDLE);

		if (sconn)
				{
						if (sconn->connection)
								{
										ret = ct_diag (sconn->connection, 
																									CS_STATUS, 
																									CS_SERVERMSG_TYPE, 
																									CS_UNUSED,
																									&msgcnt);
										if (ret != CS_SUCCEED)
												{
														sconn->err.error_msg = g_new(gchar,201);
														g_snprintf(message,
																									200,
																									"%s",
																									_("ct_diag 1 failed in sybase_check_servermsg"));
														err = gda_sybase_make_error(sconn);
														gda_server_connection_add_error(cnc,err);
														g_free((gpointer)sconn->err.error_msg);
														return TRUE;
												}
										if (!msgcnt)
												return FALSE;										
										while (msgcur < msgcnt)
												{
														msgcur++;						
														ret = ct_diag (sconn->connection, 
																													CS_GET, 
																													CS_SERVERMSG_TYPE, 
																													msgcur,
																													&msg);	
														if (ret != CS_SUCCEED)
																{
																		sconn->err.error_msg = g_new(gchar,201);
																		g_snprintf(message,
																													200,
																													"%s",
																													_("ct_diag 2 failed in sybase_check_servermsg"));
																		err = gda_sybase_make_error(sconn);
																		gda_server_connection_add_error(cnc,err);
																		g_free((gpointer)sconn->err.error_msg);
																		error_occured = TRUE;
																}

														/* for some wierd reason, severity of 10 occurs often */
														/* whenever you change databases using the 'using' SQL */
														/* command. Make sure that that message doesn't signal an error*/

														if ((msg.severity != CS_SV_INFORM) || (msg.severity != 10))
																{
																		sconn->err.error_msg = sprintf_servermsg(_("Server Message: "),
																																																											&msg);
																		err = gda_sybase_make_error(sconn);
																		gda_server_connection_add_error(cnc,err);
																		g_free((gpointer)sconn->err.error_msg);																		
																		error_occured = TRUE;
																}
														else
																{
																		/* this will just print to a debug file for now */
																		sconn->err.error_msg = 
																				sprintf_servermsg(_("Informational Server  Message: "),
																																						&msg);
																		sybase_debug_msg(sconn->err.error_msg);
																		g_free((gpointer)sconn->err.error_msg);	
																}
														/* check if we have any new messages to worry about */
														if (msgcur == msgcnt) 
																{
																		ret = ct_diag (sconn->connection, 
																																	CS_STATUS,
																																	CS_SERVERMSG_TYPE, 
																																	CS_UNUSED, 
																																	&msgcnt);
																		if (ret != CS_SUCCEED) 
																				{
																						sconn->err.error_msg = g_new(gchar,201);
																						g_snprintf(message,
																																	200,
																																	"%s",
																																	_("ct_diag 2 failed in sybase_check_servermsg"));
																						err = gda_sybase_make_error(sconn);
																						gda_server_connection_add_error(cnc,err);
																						g_free((gpointer)sconn->err.error_msg);
																						error_occured = TRUE; 			
																				} /* if ret != CS_SUCCEED */
																} /* if msgcur == msgcnt */
												} /* while msgcur < msgcnt */ 
								} /* if sconn->connection */	
				} /* if sconn */
		return error_occured;	
}
										
gboolean 
sybase_check_cmsg(GdaServerConnection *cnc)
{
		CS_RETCODE ret = CS_SUCCEED;
		CS_INT msgcnt = 0;
		CS_INT msgcur = 0;
		GdaError *err;
		gchar *message;
		gboolean error_occured = FALSE;
		CS_CLIENTMSG msg;
		sybase_connection *sconn;

		sconn = g_object_get_data(G_OBJECT(cnc),OBJECT_DATA_SYBASE_HANDLE);

		if (sconn)
				{
						if (sconn->connection)
								{
										ret = cs_diag (sconn->context, 
																									CS_STATUS, 
																									CS_CLIENTMSG_TYPE, 
																									CS_UNUSED,
																									&msgcnt);												
										if (ret != CS_SUCCEED)
												{
														sconn->err.error_msg = g_new(gchar,201);
														g_snprintf(message,
																									200,
																									"%s",
																									_("cs_diag 1 failed in sybase_check_clientmsg"));
														err = gda_sybase_make_error(sconn);
														gda_server_connection_add_error(cnc,err);
														g_free((gpointer)sconn->err.error_msg);
														return TRUE;
												}
										if (!msgcnt)
												return FALSE;
										while (msgcur < msgcnt)
												{
														msgcur++;						
														ret = cs_diag (sconn->context, 
																													CS_GET, 
																													CS_CLIENTMSG_TYPE, 
																													msgcur,
																													&msg);	
														if (ret != CS_SUCCEED)
																{
																		sconn->err.error_msg = g_new(gchar,201);
																		g_snprintf(message,
																													200,
																													"%s",
																													_("cs_diag 2 failed in sybase_check_clientmsg"));
																		err = gda_sybase_make_error(sconn);
																		gda_server_connection_add_error(cnc,err);
																		g_free((gpointer)sconn->err.error_msg);
																		error_occured = TRUE;
																}
														if (msg.severity != CS_SV_INFORM)
																{
																		sconn->err.error_msg = sprintf_clientmsg(_("Client Message: "),
																																																											&msg);
																		err = gda_sybase_make_error(sconn);
																		gda_server_connection_add_error(cnc,err);
																		g_free((gpointer)sconn->err.error_msg);																		
																		error_occured = TRUE;
																}
														else
																{
																		/* this will just print to a debug file for now */
																		sconn->err.error_msg = 
																				sprintf_clientmsg(_("Informational Client  Message: "),
																																						&msg);
																		sybase_debug_msg(sconn->err.error_msg);
																		g_free((gpointer)sconn->err.error_msg);	
																}
														/* check if we have any new messages to worry about */
														if (msgcur == msgcnt) 
																{
																		ret = cs_diag (sconn->context, 
																																	CS_STATUS,
																																	CS_CLIENTMSG_TYPE, 
																																	CS_UNUSED, 
																																	&msgcnt);
																		if (ret != CS_SUCCEED) 
																				{
																						sconn->err.error_msg = g_new(gchar,201);
																						g_snprintf(message,
																																	200,
																																	"%s",
																																	_("cs_diag 2 failed in sybase_check_clientmsg"));
																						err = gda_sybase_make_error(sconn);
																						gda_server_connection_add_error(cnc,err);
																						g_free((gpointer)sconn->err.error_msg);
																						error_occured = TRUE; 			
																				} /* if ret != CS_SUCCEED */
																} /* if msgcur == msgcnt */
												} /* while msgcur < msgcnt */ 
								} /* if sconn->connection */	
				} /* if sconn */
		return error_occured;	
}

gchar *
sprintf_clientmsg (const gchar * head, CS_CLIENTMSG * msg)
{
		GString *txt = NULL;
		gchar *junk;
		g_return_val_if_fail (msg != NULL, NULL);
		txt = g_string_new ("");
		g_return_val_if_fail (txt != NULL, NULL);
		g_string_sprintfa (txt,
																					"%s %s %s(%ld) %s(%ld) %s(%ld) %s(%ld) %s ",
																					_("SYB"),
																					head,
																					_("severity"),
																					(long) CS_SEVERITY (msg->severity),	
																					_("number"),
																					(long) CS_NUMBER (msg->msgnumber),																					
																					_("origin"),
																					(long) CS_ORIGIN (msg->msgnumber),
																					_("layer"),
																					(long) CS_LAYER (msg->msgnumber),
																					msg->msgstring);
																					    
		if (msg->osstringlen > 0) 
				{
						g_string_sprintfa (txt,
																									_("\n\tOperating system error number(%ld):\n\t%s"),
																									(long) msg->osnumber, msg->osstring);
				}		
		junk = g_strdup(txt->str);
		g_string_free(txt,TRUE);
		return (junk);
}

gchar *
sprintf_servermsg (const gchar * head, CS_SERVERMSG * msg)
{
		GString *txt = NULL;
		gchar *junk;

		g_return_val_if_fail (msg != NULL, NULL);
		txt = g_string_new ("");
		g_return_val_if_fail (txt != NULL, NULL);

		g_string_sprintfa (txt,
																					"%s\n\tnumber(%ld) severity(%ld) state(%ld) line(%ld)", 
																					head, 
																					(long) msg->msgnumber,
																					(long) msg->severity, 
																					(long) msg->state,
																					(long) msg->line);

		if (msg->svrnlen > 0)
				g_string_sprintfa (txt, "\n\tServer name: %s", msg->svrname);
		if (msg->proclen > 0)
				g_string_sprintfa (txt, "\n\tProcedure name: %s", msg->proc);
		g_string_sprintfa (txt, "\n\t%s", msg->text);		
		junk = g_strdup(txt->str);
		g_string_free(txt,TRUE);
		return (junk);
}

void sybase_debug_msg(gchar *message)
{
		FILE *foo;
		foo = fopen ("/home/projects/gda_sybase_debug.log","a+");
		fprintf(foo,"%s\n",message);
		fflush(foo);
		fclose(foo);


}






/* GDA Sybase provider
 * Copyright (C) 1998-2001 The Free Software Foundation
 *
 * AUTHORS:
	*  Mike Wingert <wingert 3 postbox acs ohio-state edu>
	*      based on the MySQL provider by
 *         Michael Lausch <michael lausch at>
 *	        Rodrigo Moya <rodrigo gnome-db org>
 *         Vivien Malerba <malerba gnome-db org>
	*
 * 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, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gda-sybase.h"

static void 
gda_sybase_provider_class_init (GdaSybaseProviderClass *klass);
static void 
gda_sybase_provider_init (GdaSybaseProvider *provider,
																										GdaSybaseProviderClass *klass);
static void 
gda_sybase_provider_finalize   (GObject *object);
static gboolean 
gda_sybase_provider_open_connection (GdaServerProvider *provider,
																																					GdaServerConnection *cnc,
																																					GdaQuarkList *params,
																																					const gchar *username,
																																					const gchar *password);
static gboolean 
gda_sybase_provider_close_connection (GdaServerProvider *provider,
																																						GdaServerConnection *cnc);
static GObjectClass *parent_class = NULL;

/*
 * GdaSybaseProvider class implementation
 */

static void
gda_sybase_provider_class_init (GdaSybaseProviderClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	GdaServerProviderClass *provider_class = GDA_SERVER_PROVIDER_CLASS (klass);

	parent_class = g_type_class_peek_parent (klass);

	object_class->finalize = gda_sybase_provider_finalize;
	provider_class->open_connection = gda_sybase_provider_open_connection;
	provider_class->close_connection = gda_sybase_provider_close_connection;
	provider_class->begin_transaction = NULL;
	provider_class->commit_transaction = NULL;
	provider_class->rollback_transaction = NULL;
}

static void
gda_sybase_provider_init (GdaSybaseProvider *myprv, 
																										GdaSybaseProviderClass *klass)
{

}

static void
gda_sybase_provider_finalize (GObject *object)
{
	GdaSybaseProvider *myprv = (GdaSybaseProvider *) object;

	g_return_if_fail (GDA_IS_SYBASE_PROVIDER (myprv));

	/* chain to parent class */
	parent_class->finalize (object);
}

GType
gda_sybase_provider_get_type (void)
{
	static GType type = 0;

	if (!type) {
		if (type == 0) {
			static GTypeInfo info = {
					sizeof (GdaSybaseProviderClass),
					(GBaseInitFunc) NULL,
					(GBaseFinalizeFunc) NULL,
					(GClassInitFunc) gda_sybase_provider_class_init,
					NULL, NULL,
					sizeof (GdaSybaseProvider),
					0,
					(GInstanceInitFunc) gda_sybase_provider_init
			};
			type = g_type_register_static (PARENT_TYPE,
						       "GdaSybaseProvider",
						       &info, 0);
		}
	}

	return type;
}

/* open_connection handler for the GdaSybaseProvider class */
static gboolean
gda_sybase_provider_open_connection (GdaServerProvider *provider,
																																					GdaServerConnection *cnc,
																																					GdaQuarkList *params,
																																					const gchar *username,
																																					const gchar *password)
{
		
		sybase_connection *sconn;
		CS_RETCODE ret;
		gchar *t_host = NULL;
		gchar *t_db = NULL;
		gchar *t_user = NULL;
		gchar *t_password = NULL;		
		CS_CHAR buf[500];
		
		/* the logic to connect to the database */

		sybase_debug_msg("about to open connection");

		if (username)
				t_user = g_strdup(username);
		else
				t_user = gda_quark_list_find (params, "USERNAME");


		if (password)
				t_password = g_strdup(password);
		else
				t_password = gda_quark_list_find (params, "PASSWORD");


		sybase_debug_msg("username password");
		sybase_debug_msg(t_user);
		sybase_debug_msg(t_password);

		sconn = g_new(sybase_connection,1);
		sconn->context = NULL;
		sconn->connection = NULL;

		ret = cs_ctx_alloc (CS_VERSION_100, &sconn->context);
		if (ret != CS_SUCCEED)
				{
						g_free((gpointer)sconn);
      return FALSE;
				}
		ret = ct_init (sconn->context, CS_VERSION_100);
		if (ret != CS_SUCCEED)
				{
						if (sconn->context)
						{
								ct_con_drop (sconn->connection);
						}
						g_free((gpointer)sconn);
						return FALSE;
				}				
		/* allocate the connection structure */
		ret = ct_con_alloc(sconn->context, &sconn->connection);
		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}						
		ret = cs_diag (sconn->context, 
																	CS_INIT, 
																	CS_UNUSED, 
																	CS_UNUSED,
																	NULL);		
		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}						
		ret = ct_diag (sconn->connection, 
																	CS_INIT, 
																	CS_UNUSED, 
																	CS_UNUSED,
																	NULL);
		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}								
		ret = ct_con_props (sconn->connection, 
                      CS_SET, 
                      CS_APPNAME, 
                      (CS_CHAR *) "libgda test", 
                      CS_NULLTERM, 
                      NULL);		
		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}						



		ret = ct_con_props(sconn->connection, 
                     CS_SET, 
                     CS_USERNAME, 
                     (CS_CHAR *) t_user,
                     CS_NULLTERM, 
                     NULL);

		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}								
		ret = ct_con_props (sconn->connection, 
                      CS_SET, 
                      CS_PASSWORD, 
                      (CS_CHAR *) t_password,
                      CS_NULLTERM, 
                      NULL);

		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}						
		ret = ct_connect (sconn->connection, 
																				(CS_CHAR *) NULL, 
																				0);
		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}						
		/* get the hostname from SQL server as a test */
		ret = ct_con_props (sconn->connection, 
                      CS_GET, 
                      CS_SERVERNAME, 
                      &buf, 
                      CS_MAX_CHAR, 
                      NULL);		
		if (ret != CS_SUCCEED)
				{
						if (sconn->connection != NULL) 
								{
										ct_con_drop (sconn->connection);
										sconn->connection = NULL;
								}
						if (sconn->context != NULL) 
								{
										ct_exit (sconn->context, CS_FORCE_EXIT);
										cs_ctx_drop (sconn->context);
										sconn->context = NULL;
								}
						return FALSE;
				}						
		return TRUE;

		
		
		g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_SYBASE_HANDLE, sconn);

		return TRUE;
}

/* close_connection handler for the GdaSybaseProvider class */
static gboolean
gda_sybase_provider_close_connection (GdaServerProvider *provider, 
																																						GdaServerConnection *cnc)
{
		sybase_connection *sconn;
		g_return_val_if_fail (GDA_IS_SYBASE_PROVIDER (provider), FALSE);
		g_return_val_if_fail (GDA_IS_SERVER_CONNECTION (cnc), FALSE);
		sconn = g_object_get_data (G_OBJECT (cnc), OBJECT_DATA_SYBASE_HANDLE);
		if (sconn->connection != NULL) 
				{
						ct_con_drop (sconn->connection);
						sconn->connection = NULL;
				}
		if (sconn->context != NULL) 
				{
						ct_exit (sconn->context, CS_FORCE_EXIT);
						cs_ctx_drop (sconn->context);
						sconn->context = NULL;
				}
	g_object_set_data (G_OBJECT (cnc), OBJECT_DATA_SYBASE_HANDLE, NULL);
	return TRUE;
}
/* GDA Sybase provider
 * Copyright (C) 1998-2001 The Free Software Foundation
 *
 * AUTHORS:
	*  Mike Wingert <wingert 3 postbox acs ohio-state edu>
	*      based on the MySQL provider by
 *         Michael Lausch <michael lausch at>
 *	        Rodrigo Moya <rodrigo gnome-db org>
 *         Vivien Malerba <malerba gnome-db org>
 *
 * 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, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#if !defined(__gda_sybase_provider_h__)
#  define __gda_sybase_provider_h__

#include <libgda/gda-server-provider.h>

G_BEGIN_DECLS

#define GDA_TYPE_SYBASE_PROVIDER            (gda_sybase_provider_get_type())
#define GDA_SYBASE_PROVIDER(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_SYBASE_PROVIDER, GdaSybaseProvider))
#define GDA_SYBASE_PROVIDER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_SYBASE_PROVIDER, GdaSybaseProviderClass))
#define GDA_IS_SYBASE_PROVIDER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, GDA_TYPE_SYBASE_PROVIDER))
#define GDA_IS_SYBASE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDA_TYPE_SYBASE_PROVIDER))

typedef struct _GdaSybaseProvider      GdaSybaseProvider;
typedef struct _GdaSybaseProviderClass GdaSybaseProviderClass;

struct _GdaSybaseProvider {
	GdaServerProvider provider;
};

struct _GdaSybaseProviderClass {
	GdaServerProviderClass parent_class;
};

GType gda_sybase_provider_get_type (void);

G_END_DECLS

#endif
/* GDA MySQL provider
 * Copyright (C) 1998-2001 The Free Software Foundation
 *
 * AUTHORS:
	*  Mike Wingert <wingert 3 postbox acs ohio-state edu>
	*      based on the MySQL provider by
 *         Michael Lausch <michael lausch at>
 *	        Rodrigo Moya <rodrigo gnome-db org>
 *         Vivien Malerba <malerba gnome-db org>
	*         and the pre gnome 2.0 sybase provider
 * 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, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#if !defined(__gda_sybase_h__)
#  define __gda_sybase_h__

#include <glib/gmacros.h>
#include <bonobo/bonobo-i18n.h>
#include <config.h>
#include <libgda/gda-server.h>
#include <gda-sybase-provider.h>
#include <ctpublic.h>
#include <cspublic.h>

G_BEGIN_DECLS

typedef struct _sybaseError
{
		gchar *error_msg;
} sybase_error;


typedef struct _sybaseConnection
{
		CS_CONTEXT    *context;
		CS_CONNECTION *connection;
		sybase_error err;
} sybase_connection; 

#define PARENT_TYPE GDA_TYPE_SERVER_PROVIDER
#define OBJECT_DATA_SYBASE_HANDLE "GDA_Sybase_SybaseHandle"
#define GDA_SYBASE_COMPONENT_FACTORY_ID "OAFIID:GNOME_Database_Sybase_ComponentFactory"
#define GDA_SYBASE_PROVIDER_ID          "OAFIID:GNOME_Database_Sybase_Provider"

/*
 * Utility functions
 */

GdaError *gda_sybase_make_error (sybase_connection *);

gboolean sybase_check_messages(GdaServerConnection *);

gboolean sybase_check_clientmsg(GdaServerConnection *);

gboolean sybase_check_servermsg(GdaServerConnection *);

gboolean sybase_check_cmsg(GdaServerConnection *);

gchar *sprintf_clientmsg(const gchar *, 
																									CS_CLIENTMSG *);

gchar *sprintf_servermsg(const gchar *,
																									CS_SERVERMSG *);

void sybase_debug_msg(gchar *);



G_END_DECLS

#endif
/* GDA sybase provider
 * Copyright (C) 1998-2001 The Free Software Foundation
 *
 * AUTHORS:
 *      mike wingert <wingert 3 postbox acs ohio-state edu>
	*      based on the MySQL provider by
 *         Michael Lausch <michael lausch at>
 *	        Rodrigo Moya <rodrigo gnome-db org>
 *         Vivien Malerba <malerba gnome-db org>
 * 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, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "gda-sybase.h"

GdaServer *gda_sybase_server = NULL;

static void
last_client_gone_cb (GdaServer *server, gpointer user_data)
{
	g_return_if_fail (GDA_IS_SERVER (server));
	g_return_if_fail (server == gda_sybase_server);

	/* terminate the program when no more clients are connected */
	gda_main_quit ();
	g_object_unref (G_OBJECT (gda_sybase_server));
}

static void
setup_factory (void)
{
	if (gda_sybase_server != NULL)
		return;

	gda_sybase_server = gda_server_new (GDA_SYBASE_COMPONENT_FACTORY_ID);
	if (!GDA_IS_SERVER (gda_sybase_server)) {
		gda_log_error (_("Could not initiate Sybase component factory"));
		exit (-1);
	}
	g_signal_connect (G_OBJECT (gda_sybase_server), "last_client_gone",
			  G_CALLBACK (last_client_gone_cb), NULL);

	/* register the components for this server */
	gda_server_register_component (gda_sybase_server,
				       GDA_SYBASE_PROVIDER_ID,
				       GDA_TYPE_SYBASE_PROVIDER);
}

int
main (int argc, char *argv[])
{
	/* initialize application */
	gda_init ("gda-sybase-srv", VERSION, argc, argv);

	setup_factory ();

	/* run the application loop */
	gda_main_run (NULL, NULL);

	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]