[2ee713]: DBD-Sybase-1.03.01 / dbdimp.dif Maximize Restore History

Download this file

dbdimp.dif    438 lines (437 with data), 14.1 kB

50d49
< DBISTATE_DECLARE;
52c51
< static perl_mutex context_alloc_mutex[1];
---
> DBISTATE_DECLARE;
72a72,73
> 
> static CS_CONTEXT *context;
75c76
< static char ocVersion[255];
---
> static char *ocVersion;
102,105c103
< 	if (connection && (ct_con_props (connection, CS_GET, CS_USERDATA, &imp_dbh, CS_SIZEOF (imp_dbh), NULL)) != CS_SUCCEED)
< 		croak ("Panic: clientmsg_cb: Can't find handle from connection");
< 
< 	if (connection && imp_dbh)
---
> 	if (connection)
106a105,106
> 		if ((ct_con_props (connection, CS_GET, CS_USERDATA, &imp_dbh, CS_SIZEOF (imp_dbh), NULL)) != CS_SUCCEED)
> 			croak ("Panic: clientmsg_cb: Can't find handle from connection");
120a121
> 
542a544
> 
581,582c583,586
< CS_CONTEXT *
< syb_alloc_ctx ()
---
> 
> void
> syb_init (dbistate)
> 	 dbistate_t *dbistate;
584c588,592
< 	CS_CONTEXT *context;
---
> 	SV *sv;
> 	CS_INT netio_type = CS_SYNC_IO;
> 	STRLEN lna;
> 	CS_INT outlen;
> 	CS_RETCODE retcode = CS_FAIL;
587d594
< 	CS_INT retcode = CS_FAIL;
589c596
< 	MUTEX_LOCK (context_alloc_mutex);
---
> 	DBIS = dbistate;
615,616d621
< 	MUTEX_UNLOCK (context_alloc_mutex);
< 
618,620c623
< 	{
< 		return NULL;
< 	}
---
> 		croak ("DBD::Sybase initialize: cs_ctx_alloc(%d) failed", cs_ver);
622c625
< 	/* warn ("make context %p version: %d", context, cs_ver); */
---
> /*    warn("context version: %d", cs_ver); */
634c637
< 		MUTEX_LOCK (context_alloc_mutex);
---
> #if 1
636,675c639,641
< 		MUTEX_UNLOCK (context_alloc_mutex);
< 		return NULL;
< 	}
< 	return context;
< }
< 
< void
< syb_drop_ctx (context)
< 	 CS_CONTEXT *context;
< {
< 	CS_INT retcode;
< 
< 	/* warn ("drop context %p", context); */
< 
< 	if (!context)
< 		return;
< 
< 	if ((retcode = ct_exit (context, CS_UNUSED)) != CS_SUCCEED)
< 		warn ("DBD::Sybase could exit context");
< 	MUTEX_LOCK (context_alloc_mutex);
< 	if ((retcode = cs_ctx_drop (context)) != CS_SUCCEED)
< 		warn ("DBD::Sybase could not drop context");
< 	MUTEX_UNLOCK (context_alloc_mutex);
< }
< 
< /* In the PerlEx environment, this is the surest way to know that the
<  * mutex is managed correctly. You're on your own for other OSes */
< BOOL WINAPI
< DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID fImpLoad)
< {
< 	switch (fdwReason)
< 	{
< 	case DLL_PROCESS_ATTACH:
< 		MUTEX_INIT (context_alloc_mutex);
< 		break;
< 	case DLL_PROCESS_DETACH:
< 		//MUTEX_DESTROY (context_alloc_mutex);
< 		break;
< 	}
< 	return TRUE;
---
> #endif
> 		context = NULL;
> 		croak ("DBD::Sybase initialize: ct_init(%d) failed", cs_ver);
678,684c644,647
< void
< syb_init (dbistate)
< 	 dbistate_t *dbistate;
< {
< 	SV *sv;
< 	STRLEN lna;
< 	CS_INT outlen;
---
> 	if ((retcode = ct_callback (context, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *) clientmsg_cb)) != CS_SUCCEED)
> 		croak ("DBD::Sybase initialize: ct_callback(clientmsg) failed");
> 	if ((retcode = ct_callback (context, NULL, CS_SET, CS_SERVERMSG_CB, (CS_VOID *) servermsg_cb)) != CS_SUCCEED)
> 		croak ("DBD::Sybase initialize: ct_callback(servermsg) failed");
686c649,650
< 	DBIS = dbistate;
---
> 	if ((retcode = ct_config (context, CS_SET, CS_NETIO, &netio_type, CS_UNUSED, NULL)) != CS_SUCCEED)
> 		croak ("DBD::Sybase initialize: ct_config(netio) failed");
688,689c652,656
< 	/* Note we really need to call MUTEX_DESTROY(m), but where? */
< 	/* warn("This is Gene Ressler's version!"); */
---
> #if defined(MAX_CONNECT)
> 	netio_type = MAX_CONNECT;
> 	if ((retcode = ct_config (context, CS_SET, CS_MAX_CONNECT, &netio_type, CS_UNUSED, NULL)) != CS_SUCCEED)
> 		croak ("DBD::Sybase initialize: ct_config(max_connect) failed");
> #endif
691,700d657
< 	{							/* Fetch version string. */
< 		CS_CONTEXT *context;
< 		char *p;
< 		if ((context = syb_alloc_ctx ()) == NULL)
< 		{
< 			/* This apparently can happen in PerlEx if SQL Server starts more slowly than PerlEx. */
< 			warn ("DBD::Sybase could not make context to fetch version");
< 			strcpy (ocVersion, "Sybase client version not available");
< 		}
< 		else
702,704c659,661
< 
< 			ct_config (context, CS_GET, CS_VER_STRING, (CS_VOID *) ocVersion, sizeof ocVersion, &outlen);
< 			if ((p = strchr (ocVersion, '\n')))
---
> 		char out[1024], *p;
> 		retcode = ct_config (context, CS_GET, CS_VER_STRING, (CS_VOID *) out, 1024, &outlen);
> 		if ((p = strchr (out, '\n')))
706,707c663,664
< 			syb_drop_ctx (context);
< 		}
---
> 
> 		ocVersion = my_strdup (out);
743d699
< #ifdef DEPRECATED
759c715
< #endif
---
> 
825,827d780
< 	imp_dbh->context = NULL;
< 	imp_dbh->locale = NULL;
< 	imp_dbh->connection = NULL;
904a858,859
> 	CS_CONNECTION *connection = NULL;
> 	CS_LOCALE *locale = NULL;
907,986d861
< 	CS_INT netio_type = CS_SYNC_IO;
< 
< 	CS_CONNECTION *connection = NULL;
< 
< 	/* Remove the locale and context from the handle
< 	   while we make the connection.  We'll put them
< 	   back when we're done with them at the end! In
< 	   the mean time, if we return early on error,
< 	   we can drop context and locale, and the handle
< 	   will not contain dead pointers. */
< 	CS_CONTEXT *context = imp_dbh->context;
< 	CS_LOCALE *locale = imp_dbh->locale;
< 	imp_dbh->context = NULL;
< 	imp_dbh->locale = NULL;
< 
< 	if (context == NULL)
< 	{
< 
< 		if ((context = syb_alloc_ctx ()) == NULL)
< 			croak ("DBD::Sybase initialize: can't make a context");
< 
< 		/* If we can't get a context, further running is probably hopeless, so croak. */
< 		if ((retcode = ct_callback (context, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *) clientmsg_cb)) != CS_SUCCEED)
< 			croak ("DBD::Sybase initialize: ct_callback(clientmsg) failed");
< 		if ((retcode = ct_callback (context, NULL, CS_SET, CS_SERVERMSG_CB, (CS_VOID *) servermsg_cb)) != CS_SUCCEED)
< 			croak ("DBD::Sybase initialize: ct_callback(servermsg) failed");
< 		if ((retcode = ct_config (context, CS_SET, CS_NETIO, &netio_type, CS_UNUSED, NULL)) != CS_SUCCEED)
< 			croak ("DBD::Sybase initialize: ct_config(netio) failed");
< 
< #if defined(MAX_CONNECT)
< 		netio_type = MAX_CONNECT;
< 		if ((retcode = ct_config (context, CS_SET, CS_MAX_CONNECT, &netio_type, CS_UNUSED, NULL)) != CS_SUCCEED)
< 			croak ("DBD::Sybase initialize: ct_config(max_connect) failed");
< #endif
< 
< 		if (locale == NULL)
< 		{
< 			CS_INT type = CS_DATES_SHORT;
< 
< 			/* Set up the proper locale - to handle character sets, etc. */
< 			if ((retcode = cs_loc_alloc (context, &locale) != CS_SUCCEED))
< 				croak ("cs_loc_alloc failed");
< 
< 			if (cs_locale (context, CS_SET, locale, CS_LC_ALL, (CS_CHAR *) NULL, CS_UNUSED, (CS_INT *) NULL) != CS_SUCCEED)
< 				croak ("cs_locale(CS_LC_ALL) failed");
< 
< 			if (imp_dbh->language[0] != 0)
< 			{
< 				if (DBIS->debug >= 2)
< 					PerlIO_printf (DBILOGFP, "    syb_db_login() -> cs_locale(CS_SYB_LANG,%s)\n", imp_dbh->language);
< 				if (cs_locale (context, CS_SET, locale, CS_SYB_LANG, (CS_CHAR *) imp_dbh->language, CS_NULLTERM, (CS_INT *) NULL) != CS_SUCCEED)
< 				{
< 					warn ("cs_locale(CS_SYB_LANG, %s) failed", imp_dbh->language);
< 					cs_loc_drop (context, locale);
< 					syb_drop_ctx (context);
< 					return NULL;
< 				}
< 			}
< 			if (imp_dbh->charset[0] != 0)
< 			{
< 				if (DBIS->debug >= 2)
< 					PerlIO_printf (DBILOGFP, "    syb_db_login() -> cs_locale(CS_SYB_CHARSET,%s)\n", imp_dbh->charset);
< 				if (cs_locale (context, CS_SET, locale, CS_SYB_CHARSET, (CS_CHAR *) imp_dbh->charset, CS_NULLTERM, (CS_INT *) NULL) != CS_SUCCEED)
< 				{
< 					warn ("cs_locale(CS_SYB_CHARSET, %s) failed", imp_dbh->charset);
< 					cs_loc_drop (context, locale);
< 					syb_drop_ctx (context);
< 					return NULL;
< 				}
< 			}
< 
< 			if (cs_dt_info (context, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, (CS_VOID *) & type, CS_SIZEOF (CS_INT), NULL) != CS_SUCCEED)
< 			{
< 				warn ("cs_dt_info() failed");
< 				cs_loc_drop (context, locale);
< 				syb_drop_ctx (context);
< 				return NULL;
< 			}
< 		}
< 	}
999,1000d873
< 				cs_loc_drop (context, locale);
< 				syb_drop_ctx (context);
1027a901,941
> 	if (imp_dbh->locale == NULL)
> 	{
> 		CS_INT type = CS_DATES_SHORT;
> 
> 		/* Set up the proper locale - to handle character sets, etc. */
> 		if ((retcode = cs_loc_alloc (context, &locale) != CS_SUCCEED))
> 		{
> 			warn ("cs_loc_alloc failed");
> 			return 0;
> 		}
> 		if (cs_locale (context, CS_SET, locale, CS_LC_ALL, (CS_CHAR *) NULL, CS_UNUSED, (CS_INT *) NULL) != CS_SUCCEED)
> 		{
> 			warn ("cs_locale(CS_LC_ALL) failed");
> 			return 0;
> 		}
> 		if (imp_dbh->language[0] != 0)
> 		{
> 			if (DBIS->debug >= 2)
> 				PerlIO_printf (DBILOGFP, "    syb_db_login() -> cs_locale(CS_SYB_LANG,%s)\n", imp_dbh->language);
> 			if (cs_locale (context, CS_SET, locale, CS_SYB_LANG, (CS_CHAR *) imp_dbh->language, CS_NULLTERM, (CS_INT *) NULL) != CS_SUCCEED)
> 			{
> 				warn ("cs_locale(CS_SYB_LANG, %s) failed", imp_dbh->language);
> 				return 0;
> 			}
> 		}
> 		if (imp_dbh->charset[0] != 0)
> 		{
> 			if (DBIS->debug >= 2)
> 				PerlIO_printf (DBILOGFP, "    syb_db_login() -> cs_locale(CS_SYB_CHARSET,%s)\n", imp_dbh->charset);
> 			if (cs_locale (context, CS_SET, locale, CS_SYB_CHARSET, (CS_CHAR *) imp_dbh->charset, CS_NULLTERM, (CS_INT *) NULL) != CS_SUCCEED)
> 			{
> 				warn ("cs_locale(CS_SYB_CHARSET, %s) failed", imp_dbh->charset);
> 				return 0;
> 			}
> 		}
> 
> 		if (cs_dt_info (context, CS_SET, locale, CS_DT_CONVFMT, CS_UNUSED, (CS_VOID *) & type, CS_SIZEOF (CS_INT), NULL) != CS_SUCCEED)
> 			warn ("cs_dt_info() failed");
> 
> 		imp_dbh->locale = locale;
> 	}
1032,1033d945
< 		cs_loc_drop (context, locale);
< 		syb_drop_ctx (context);
1037c949
< 	if (ct_con_props (connection, CS_SET, CS_LOC_PROP, (CS_VOID *) locale, CS_UNUSED, (CS_INT *) NULL) != CS_SUCCEED)
---
> 	if (ct_con_props (connection, CS_SET, CS_LOC_PROP, (CS_VOID *) imp_dbh->locale, CS_UNUSED, (CS_INT *) NULL) != CS_SUCCEED)
1040,1042d951
< 		ct_con_drop (connection);
< 		cs_loc_drop (context, locale);
< 		syb_drop_ctx (context);
1049,1051d957
< 		ct_con_drop (connection);
< 		cs_loc_drop (context, locale);
< 		syb_drop_ctx (context);
1092,1094d997
< 			ct_con_drop (connection);
< 			cs_loc_drop (context, locale);
< 			syb_drop_ctx (context);
1104,1106d1006
< 			ct_con_drop (connection);
< 			cs_loc_drop (context, locale);
< 			syb_drop_ctx (context);
1116,1118d1015
< 			ct_con_drop (connection);
< 			cs_loc_drop (context, locale);
< 			syb_drop_ctx (context);
1127,1129d1023
< 			ct_con_drop (connection);
< 			cs_loc_drop (context, locale);
< 			syb_drop_ctx (context);
1135,1137d1028
< 			ct_con_drop (connection);
< 			cs_loc_drop (context, locale);
< 			syb_drop_ctx (context);
1149,1151d1039
< 				ct_con_drop (connection);
< 				cs_loc_drop (context, locale);
< 				syb_drop_ctx (context);
1162c1050
< 			ct_con_drop (connection);
---
> 			if (locale != NULL)
1164c1052
< 			syb_drop_ctx (context);
---
> 			ct_con_drop (connection);
1181c1069
< 			ct_con_drop (connection);
---
> 			if (locale != NULL)
1183c1071,1072
< 			syb_drop_ctx (context);
---
> 			ct_con_drop (connection);
> 
1231,1235d1119
< 	/* Install the locale and context now that we know the connection will
< 	   eventually be disconnected. */
< 	imp_dbh->locale = locale;
< 	imp_dbh->context = context;
< 
1332c1216
< 	if (cs_dt_info (imp_dbh->context, CS_SET, imp_dbh->locale, CS_DT_CONVFMT, CS_UNUSED, (CS_VOID *) & type, CS_SIZEOF (CS_INT), NULL) != CS_SUCCEED)
---
> 	if (cs_dt_info (context, CS_SET, imp_dbh->locale, CS_DT_CONVFMT, CS_UNUSED, (CS_VOID *) & type, CS_SIZEOF (CS_INT), NULL) != CS_SUCCEED)
1520a1405,1406
> 	if (imp_dbh->locale && (retcode = cs_loc_drop (context, imp_dbh->locale)) != CS_SUCCEED)
> 		PerlIO_printf (DBILOGFP, "    syb_db_disconnect(): cs_loc_drop() failed\n");
1523d1408
< 	imp_dbh->connection = NULL;
1536,1537d1420
< 	CS_RETCODE retcode;
< 
1540,1548c1423
< 
< 	/* Nothing in imp_dbh to be freed.  Woops! Now there is... ekr.   */
< 
< 	if (imp_dbh->locale && (retcode = cs_loc_drop (imp_dbh->context, imp_dbh->locale)) != CS_SUCCEED)
< 		PerlIO_printf (DBILOGFP, "    syb_db_destroy(): cs_loc_drop() failed\n");
< 	imp_dbh->locale = NULL;
< 
< 	syb_drop_ctx (imp_dbh->context);
< 	imp_dbh->context = NULL;
---
> 	/* Nothing in imp_dbh to be freed   */
2055,2056d1929
< 	if (connection == NULL)
< 		croak ("syb_alloc_cmd: missing connection");
2062d1934
< 	/* warn("\nallocate command %p", cmd); */
2072c1944,1945
< 	{ DEFAULT, LITERAL, COMMENT, LINE_COMMENT, VARIABLE };
---
> 	{ DEFAULT, LITERAL, COMMENT, LINE_COMMENT, VARIABLE }
> 	STATES;
2310,2311d2182
< 			/* warn("make command %p", imp_sth->cmd); */
< 
2391d2261
< 			/* warn("make command %p", imp_sth->cmd); */
2800d2669
< 			/* warn("make command %p", imp_sth->cmd); */
3207,3213c3076
< 	/* warn("\ndrop command %p", imp_sth->cmd); */
< 	/* Sybase automagically drops all commands associated with a connection.  
< 	   So we must check here to ensure our work has not already been done! */
< 	if (imp_dbh->connection != NULL && imp_sth->cmd != NULL && (ret = ct_cmd_drop (imp_sth->cmd)) != CS_SUCCEED)
< 		warn ("error dropping command");
< 	imp_sth->cmd = NULL;
< 
---
> 	ret = ct_cmd_drop (imp_sth->cmd);
3226d3088
< 		imp_sth->connection = NULL;
3661c3523
< to_numeric (str, context, locale, datafmt, type)
---
> to_numeric (str, locale, datafmt, type)
3664d3525
< 	 CS_CONTEXT *context;
3746c3607
< to_money (str, context, locale)
---
> to_money (str, locale)
3748d3608
< 	 CS_CONTEXT *context;
3901c3761
< 			n_value = to_numeric (phs->sv_buf, imp_dbh->context, imp_dbh->locale, &phs->datafmt, imp_sth->type);
---
> 			n_value = to_numeric (phs->sv_buf, imp_dbh->locale, &phs->datafmt, imp_sth->type);
3908c3768
< 			m_value = to_money (phs->sv_buf, imp_dbh->context, imp_dbh->locale);
---
> 			m_value = to_money (phs->sv_buf, imp_dbh->locale);