⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsql.c

📁 firebird源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    case nod_agg_total2: verb = "agg_total2";	break;    case nod_divide2:	verb = "divide2";	break;    case nod_gen_id2:   verb = "gen_id2";       break;    case nod_multiply2: verb = "multiply2";	break;    case nod_subtract2:	verb = "subtract2";	break;    case nod_limit:	verb = "limit";		break;    /* CVC: New node breakleave. */    case nod_breakleave:	verb = "breakleave";	break;    case nod_aggregate:	verb = "aggregate";	PRINTF ("%s%s\n", buffer, verb);	context = (CTX) node->nod_arg [e_agg_context];	PRINTF ("%s   context %d\n", buffer, context->ctx_context);	if ((map = context->ctx_map) != NULL)	    PRINTF ("%s   map\n", buffer);	while (map)	    {	    PRINTF ("%s      position %d\n", buffer, map->map_position);	    DSQL_pretty (map->map_node, column + 2);	    map = map->map_next;	    }	DSQL_pretty (node->nod_arg [e_agg_group], column + 1);	DSQL_pretty (node->nod_arg [e_agg_rse], column + 1);	FREE_MEM_RETURN;    case nod_constant:	verb = "constant";	if (node->nod_desc.dsc_address)	    {	    if (node->nod_desc.dsc_dtype == dtype_text)		sprintf (s, "constant \"%s\"", node->nod_desc.dsc_address);	    else		sprintf (s, "constant %d", *(SLONG*) (node->nod_desc.dsc_address));	    verb = s;	    }	break;    case nod_field:	context = (CTX) node->nod_arg [e_fld_context];	relation = context->ctx_relation;	field = (FLD) node->nod_arg [e_fld_field];	PRINTF ("%sfield %s.%s, context %d\n", buffer,		relation->rel_name, field->fld_name, context->ctx_context);	FREE_MEM_RETURN;    case nod_field_name:	PRINTF ("%sfield name: \"", buffer);	string = (STR) node->nod_arg [e_fln_context];	if (string)	    PRINTF ("%s.", string->str_data);	string = (STR) node->nod_arg [e_fln_name];	PRINTF ("%s\"\n", string->str_data);	FREE_MEM_RETURN;    case nod_map:	verb = "map";	PRINTF ("%s%s\n", buffer, verb);	context = (CTX) node->nod_arg [e_map_context];	PRINTF ("%s   context %d\n", buffer, context->ctx_context);	for (map = (MAP) node->nod_arg [e_map_map]; map; map = map->map_next)	    {	    PRINTF ("%s   position %d\n", buffer, map->map_position);	    DSQL_pretty (map->map_node, column + 1);	    }	FREE_MEM_RETURN;    case nod_position:	PRINTF ("%sposition %d\n", buffer, *ptr);	FREE_MEM_RETURN;    case nod_relation:	context = (CTX) node->nod_arg [e_rel_context];	relation = context->ctx_relation;	PRINTF ("%srelation %s, context %d\n",		buffer, relation->rel_name, context->ctx_context);	FREE_MEM_RETURN;    case nod_variable:	variable = (VAR) node->nod_arg [e_var_variable];	PRINTF ("%svariable %s %d\n", buffer, variable->var_name);	FREE_MEM_RETURN;    case nod_var_name:	PRINTF ("%svariable name: \"", buffer);	string = (STR) node->nod_arg [e_vrn_name];	PRINTF ("%s\"\n", string->str_data);	FREE_MEM_RETURN;    case nod_udf:	PRINTF ("%sfunction: \"", buffer);	string = (STR) node->nod_arg [e_udf_name];	ptr++;	PRINTF ("%s\"\n", string->str_data);	if (node->nod_count == 2)	    DSQL_pretty (*ptr, column + 1);	FREE_MEM_RETURN;    default:	sprintf (s, "unknown type %d", node->nod_type);	verb = s;    }if (node->nod_desc.dsc_dtype)    PRINTF ("%s%s (%d,%d,%x)\n",	buffer, verb,	node->nod_desc.dsc_dtype,	node->nod_desc.dsc_length,	node->nod_desc.dsc_address);else    PRINTF ("%s%s\n", buffer, verb);++column;while (ptr < end)    DSQL_pretty (*ptr++, column);FREE_MEM_RETURN;}#endif#ifdef  WINDOWS_ONLYvoid    DSQL_wep( void){/************************************** * *      D S Q L _ w e p * ************************************** * * Functional description *      Call cleanup for WEP. * **************************************/cleanup (NULL);}#endifstatic void cleanup (    void	*arg){/************************************** * *	c l e a n u p * ************************************** * * Functional Description *	exit handler for local dsql image * **************************************/if (init_flag)    {    init_flag = FALSE;    databases = open_cursors = NULL_PTR;    HSHD_fini();    ALLD_fini();    }}static void cleanup_database (    SLONG	**db_handle,    SLONG	flag){/************************************** * *	c l e a n u p _ d a t a b a s e * ************************************** * * Functional description *	Clean up DSQL globals. * * N.B., the cleanup handlers (registered with gds__database_cleanup) * are called outside of the ISC thread mechanism... * * These do not make use of the context at this time. * **************************************/DBB	*dbb_ptr, dbb;STATUS	user_status [ISC_STATUS_LENGTH];USHORT	i;if (!db_handle || !databases)    return;THD_MUTEX_LOCK (&databases_mutex);for (dbb_ptr = &databases; dbb = *dbb_ptr; dbb_ptr = &dbb->dbb_next)    if (dbb->dbb_database_handle == *db_handle)	{	*dbb_ptr = dbb->dbb_next;	dbb->dbb_next = NULL;	break;	}if (dbb)    {    if (flag)	{	THREAD_EXIT;	for (i = 0; i < irq_MAX; i++)	    if (dbb->dbb_requests [i])		isc_release_request (user_status, GDS_REF (dbb->dbb_requests [i]));	THREAD_ENTER;	}    HSHD_finish (dbb);    ALLD_rlpool (dbb->dbb_pool);    }if (!databases)    {    if (!databases)	{        cleanup (NULL_PTR);	gds__unregister_cleanup (cleanup, NULL_PTR);	}    }THD_MUTEX_UNLOCK (&databases_mutex);}static void cleanup_transaction (    SLONG	*tra_handle,    SLONG	arg){/************************************** * *	c l e a n u p _ t r a n s a c t i o n * ************************************** * * Functional description *	Clean up after a transaction.  This means *	closing all open cursors. * **************************************/STATUS	local_status [ISC_STATUS_LENGTH];OPN	*open_cursor_ptr, open_cursor;/* find this transaction/request pair in the list of pairs */THD_MUTEX_LOCK (&cursors_mutex);open_cursor_ptr = &open_cursors;while (open_cursor = *open_cursor_ptr)    if (open_cursor->opn_transaction == tra_handle)	{	/* Found it, close the cursor but don't remove it from the list.	   The close routine will have done that. */	THD_MUTEX_UNLOCK (&cursors_mutex);	/*	 * we are expected to be within the subsystem when we do this	 * cleanup, for now do a thread_enter/thread_exit here.	 * Note that the function GDS_DSQL_FREE() calls the local function.	 * Over the long run, it might be better to move the subsystem_exit()	 * call in why.c below the cleanup handlers. smistry 9-27-98	 */	THREAD_ENTER;	GDS_DSQL_FREE (local_status, &open_cursor->opn_request, DSQL_close);	THREAD_EXIT;	THD_MUTEX_LOCK (&cursors_mutex);	open_cursor_ptr = &open_cursors;	}    else	open_cursor_ptr = &open_cursor->opn_next;THD_MUTEX_UNLOCK (&cursors_mutex);}static void close_cursor (    REQ		request){/************************************** * *	c l o s e _ c u r s o r * ************************************** * * Functional description *	Close an open cursor. * **************************************/OPN	*open_cursor_ptr, open_cursor;STATUS	status_vector [ISC_STATUS_LENGTH];if (request->req_handle)    {    THREAD_EXIT;    if (request->req_type == REQ_GET_SEGMENT ||	request->req_type == REQ_PUT_SEGMENT)	isc_close_blob (status_vector, GDS_REF (request->req_handle));    else	isc_unwind_request (status_vector, GDS_REF (request->req_handle), 0);    THREAD_ENTER;    }request->req_flags &= ~(REQ_cursor_open | REQ_embedded_sql_cursor);/* Remove the open cursor from the list */THD_MUTEX_LOCK (&cursors_mutex);open_cursor_ptr = &open_cursors;for (; open_cursor = *open_cursor_ptr; open_cursor_ptr = &open_cursor->opn_next)    if (open_cursor == request->req_open_cursor)	{	*open_cursor_ptr = open_cursor->opn_next;	break;	}THD_MUTEX_UNLOCK (&cursors_mutex);if (open_cursor)    {    ALLD_release (open_cursor);    request->req_open_cursor = NULL;    }}static USHORT convert (    SLONG	number,    SCHAR	*buffer){/************************************** * *	c o n v e r t * ************************************** * * Functional description *	Convert a number to VAX form -- least significant bytes first. *	Return the length. * **************************************/SLONG	n;SCHAR	*p;#ifdef VAXn = number;p = (SCHAR*) &n;*buffer++ = *p++;*buffer++ = *p++;*buffer++ = *p++;*buffer++ = *p++;#elsep = (SCHAR*) (&number + 1);*buffer++ = *--p;*buffer++ = *--p;*buffer++ = *--p;*buffer++ = *--p;#endifreturn 4;}static STATUS error (void){/************************************** * *	e r r o r * ************************************** * * Functional description *	An error returned has been trapped. * **************************************/TSQL	tdsql;tdsql = GET_THREAD_DATA;return tdsql->tsql_status [1];}static void execute_blob (    REQ		request,    int		**trans_handle,    USHORT	in_blr_length,    UCHAR	*in_blr,    USHORT	in_msg_length,    UCHAR	*in_msg,    USHORT	out_blr_length,    UCHAR	*out_blr,    USHORT	out_msg_length,    UCHAR	*out_msg){/************************************** * *	e x e c u t e _ b l o b * ************************************** * * Functional description *	Open or create a blob. * **************************************/BLB		blob;SSHORT		filter;USHORT		bpb_length;GDS__QUAD	*blob_id;UCHAR		bpb [24], *p;PAR		parameter, null;STATUS		s;TSQL		tdsql;tdsql = GET_THREAD_DATA;blob = request->req_blob;map_in_out (request, blob->blb_open_in_msg, in_blr_length, in_blr, in_msg_length, in_msg);p = bpb;*p++ = gds__bpb_version1;if (filter = filter_sub_type (request, blob->blb_to))    {    *p++ = gds__bpb_target_type;    *p++ = 2;    *p++ = filter;    *p++ = filter >> 8;    }if (filter = filter_sub_type (request, blob->blb_from))    {    *p++ = gds__bpb_source_type;    *p++ = 2;    *p++ = filter;    *p++ = filter >> 8;    }bpb_length = p - bpb;if (bpb_length == 1)    bpb_length = 0;parameter = blob->blb_blob_id;null = parameter->par_null;if (request->req_type == REQ_GET_SEGMENT)    {    blob_id = (GDS__QUAD*) parameter->par_desc.dsc_address;    if (null && *((SSHORT*) null->par_desc.dsc_address) < 0)	memset (blob_id, 0, sizeof (GDS__QUAD));    THREAD_EXIT;    s = isc_open_blob2 (tdsql->tsql_status,	    GDS_REF (request->req_dbb->dbb_database_handle),	    GDS_REF (request->req_trans),	    GDS_REF (request->req_handle),	    GDS_VAL (blob_id),	    bpb_length,	    bpb);    THREAD_ENTER;    if (s)	punt();    }else    {    request->req_handle = NULL;    blob_id = (GDS__QUAD*) parameter->par_desc.dsc_address;    memset (blob_id, 0, sizeof (GDS__QUAD));    THREAD_EXIT;    s = isc_create_blob2 (tdsql->tsql_status,	    GDS_REF (request->req_dbb->dbb_database_handle),	    GDS_REF (request->req_trans),	    GDS_REF (request->req_handle),	    GDS_VAL (blob_id),	    bpb_length,	    bpb);    THREAD_ENTER;    if (s)	punt();    map_in_out (NULL, blob->blb_open_out_msg, out_blr_length, out_blr, out_msg_length, out_msg);    }}static	STATUS	execute_request (    REQ		request,    int		**trans_handle,    USHORT	in_blr_length,    UCHAR	*in_blr,    USHORT	in_msg_length,    UCHAR	*in_msg,    USHORT	out_blr_length,    UCHAR	*out_blr,    USHORT	out_msg_length,    UCHAR	*out_msg,    USHORT	singleton){/************************************** * *	e x e c u t e _ r e q u e s t * ************************************** * * Functional description *	Execute a dynamic SQL statement. * **************************************/MSG	message;USHORT	use_msg_length;UCHAR	*use_msg;SCHAR	buffer [20];STATUS	s, local_status [ISC_STATUS_LENGTH];TSQL	tdsql;STATUS	return_status;tdsql = GET_THREAD_DATA;request->req_trans = (int *) *trans_handle;return_status = SUCCESS;switch (request->req_type)    {    case REQ_START_TRANS:	THREAD_EXIT;	s = isc_start_transaction (tdsql->tsql_status,		&request->req_trans,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -