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

📄 oci8.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	oci_debug("OCIloadlob: size=%d",siz);	return 0;}/* }}} *//* {{{ oci_failover_callback() */#if 0 /* not needed yet ! */static sb4 oci_failover_callback(dvoid *svchp,						dvoid* envhp,						dvoid *fo_ctx,						ub4 fo_type,						ub4 fo_event){	/* 	   this stuff is from an oci sample - it will get cleaned up as soon as i understand it!!! (thies@thieso.net 990420) 	   right now i cant get oracle to even call it;-(((((((((((	*/	switch (fo_event)		{		case OCI_FO_BEGIN:			{				printf(" Failing Over ... Please stand by \n");				printf(" Failover type was found to be %s \n",						((fo_type==OCI_FO_NONE) ? "NONE"						:(fo_type==OCI_FO_SESSION) ? "SESSION"						:(fo_type==OCI_FO_SELECT) ? "SELECT"						: "UNKNOWN!"));				printf(" Failover Context is :%s\n",						(fo_ctx?(char *)fo_ctx:"NULL POINTER!"));				break;			}					case OCI_FO_ABORT:			{				printf(" Failover aborted. Failover will not take place.\n");				break;			}					case OCI_FO_END:			{				printf(" Failover ended ...resuming services\n");				break;			}					case OCI_FO_REAUTH:			{				printf(" Failed over user. Resuming services\n");								/* Application can check the OCI_ATTR_SESSION attribute of				   the service handle to find out the user being				   re-authenticated.				   				   After this, the application can replay any ALTER SESSION				   commands associated with this session.  These must have				   been saved by the application in the fo_ctx				*/				break;			}								case OCI_FO_ERROR:			{				printf(" Failover error gotten. Sleeping...\n");				php_sleep(3);				/* cannot find this blody define !!! return OCI_FO_RETRY; */				break;			}					default:			{				printf("Bad Failover Event: %ld.\n",  fo_event);				break;			}		}	return 0;  }#endif/* }}} *//* {{{ oci_bind_in_callback() */static sb4oci_bind_in_callback(dvoid *ictxp,     /* context pointer */					 OCIBind *bindp,   /* bind handle */					 ub4 iter,         /* 0-based execute iteration value */					 ub4 index,        /* index of current array for PL/SQL or row index for SQL */					 dvoid **bufpp,    /* pointer to data */					 ub4 *alenp,       /* size after value/piece has been read */					 ub1 *piecep,      /* which piece */					 dvoid **indpp)    /* indicator value */{	oci_bind *phpbind;	zval *val;	TSRMLS_FETCH();	if (!(phpbind=(oci_bind *)ictxp) || !(val = phpbind->zval)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "!phpbind || !phpbind->val");		return OCI_ERROR;	}	if (ZVAL_IS_NULL(val)) {		/* we're going to insert a NULL column */		phpbind->indicator = -1;		*bufpp = 0;		*alenp = -1;		*indpp = (dvoid *)&phpbind->indicator;	} else 	if ((phpbind->descr == 0) && (phpbind->pStmt == 0)) {		/* "normal string bind */		convert_to_string(val); 		*bufpp = Z_STRVAL_P(val);		*alenp = Z_STRLEN_P(val);		*indpp = (dvoid *)&phpbind->indicator;	} else if (phpbind->pStmt != 0) {		/* RSET */		*bufpp = phpbind->pStmt;		*alenp = -1;		/* seems to be allright */		*indpp = (dvoid *)&phpbind->indicator;	} else { 		/* descriptor bind */		*bufpp = phpbind->descr;		*alenp = -1;		/* seems to be allright */		*indpp = (dvoid *)&phpbind->indicator;	}	*piecep = OCI_ONE_PIECE; /* pass all data in one go */	return OCI_CONTINUE;}/* }}} *//* {{{ oci_bind_out_callback() */static sb4oci_bind_out_callback(dvoid *octxp,      /* context pointer */					  OCIBind *bindp,    /* bind handle */					  ub4 iter,          /* 0-based execute iteration value */					  ub4 index,         /* index of current array for PL/SQL or row index for SQL */					  dvoid **bufpp,     /* pointer to data */					  ub4 **alenpp,      /* size after value/piece has been read */					  ub1 *piecep,       /* which piece */					  dvoid **indpp,     /* indicator value */					  ub2 **rcodepp)     /* return code */{	oci_bind *phpbind;	zval *val;	sb4 retval = OCI_ERROR;	TSRMLS_FETCH();	if (!(phpbind=(oci_bind *)octxp) || !(val = phpbind->zval)) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "!phpbind || !phpbind->val");		return retval;	}	if ((Z_TYPE_P(val) == IS_OBJECT) || (Z_TYPE_P(val) == IS_RESOURCE)) {		retval = OCI_CONTINUE;	} else {		convert_to_string(val);		zval_dtor(val);				Z_STRLEN_P(val) = OCI_PIECE_SIZE; /* 64K-1 is max XXX */		Z_STRVAL_P(val) = emalloc(Z_STRLEN_P(phpbind->zval));				/* XXX we assume that zend-zval len has 4 bytes */		*alenpp = (ub4*) &Z_STRLEN_P(phpbind->zval); 		*bufpp = Z_STRVAL_P(phpbind->zval);		*piecep = OCI_ONE_PIECE;		*rcodepp = &phpbind->retcode;		*indpp = &phpbind->indicator;		retval = OCI_CONTINUE;	}	return retval;}/* }}} *//* {{{ _oci_open_session() */#include "ext/standard/php_smart_str.h"static oci_session *_oci_open_session(oci_server* server,char *username,char *password,int persistent,int exclusive,char *charset){	oci_session *session = 0, *psession = 0;	OCISvcCtx *svchp = 0;	smart_str hashed_details = {0};#ifdef HAVE_OCI_9_2	ub2 charsetid = 0;#endif	TSRMLS_FETCH();	/* 	   check if we already have this user authenticated	   we will reuse authenticated users within a request no matter if the user requested a persistent 	   connections or not!	   	   but only as persistent requested connections will be kept between requests!	*/#if defined(HAVE_OCI_9_2)	if (*charset) {		smart_str_appends_ex(&hashed_details, charset, 1);	} else {		size_t rsize;		/* Safe, charsetid is initialized to 0 */		CALL_OCI(OCINlsEnvironmentVariableGet(&charsetid, 				2, 				OCI_NLS_CHARSET_ID, 				0,				&rsize));		smart_str_append_long_ex(&hashed_details, charsetid, 1);		charsetid = 0;	}#else	{		char *nls_lang = getenv("NLS_LANG");		/* extract charset from NLS_LANG=LANUAGE_TERRITORY.CHARSET */		if (nls_lang) {			char *p = strchr(nls_lang, '.');			if (p) {				smart_str_appends_ex(&hashed_details, p + 1, 1);			}		}	}#endif	smart_str_appends_ex(&hashed_details, SAFE_STRING(username), 1);	smart_str_appends_ex(&hashed_details, SAFE_STRING(password), 1);	smart_str_appends_ex(&hashed_details, SAFE_STRING(server->dbname), 1);	smart_str_0(&hashed_details);	if (! exclusive) {		zend_hash_find(OCI(user), hashed_details.c, hashed_details.len+1, (void **) &session);		if (session) {			if (session->is_open) {				if (persistent) {					session->persistent = 1;				}				smart_str_free_ex(&hashed_details, 1);				return session;			} else {				_oci_close_session(session);				/* breakthru to open */			}		}	}	session = calloc(1,sizeof(oci_session));	if (! session) {		goto CLEANUP;	}	session->persistent = persistent;	session->hashed_details = hashed_details.c;	session->server = server;	session->exclusive = exclusive;#ifdef HAVE_OCI_9_2	/* following chunk is Oracle 9i+ ONLY */	if (*charset) {		/*		   get ub2 charset id based on charset		   this is pretty secure, since if we don't have a valid character set name,		   0 comes back and we can still use the 0 in all further statements -> OCI uses NLS_LANG		   setting in that case		*/		CALL_OCI_RETURN(charsetid, OCINlsCharSetNameToId(							OCI(pEnv),							charset));				oci_debug("oci_do_connect: using charset id=%d",charsetid);	}	session->charsetId = charsetid;		/* create an environment using the character set id, Oracle 9i+ ONLY */	CALL_OCI(OCIEnvNlsCreate(				&session->pEnv,				PHP_OCI_INIT_MODE, 				0, 				NULL,				NULL,				NULL,				0,				NULL,				charsetid,				charsetid));#else	/* fallback solution (simply use global env and charset, same behaviour as always been) */	session->pEnv = OCI(pEnv);	session->charsetId = 0;#endif  /* HAVE_OCI_9_2 */	/* allocate temporary Service Context */	CALL_OCI_RETURN(OCI(error), OCIHandleAlloc(				session->pEnv, 				(dvoid **)&svchp, 				OCI_HTYPE_SVCCTX, 				0, 				NULL));		if (OCI(error) != OCI_SUCCESS) {		oci_error(OCI(pError), "_oci_open_session: OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI(error));		goto CLEANUP;	}	/* allocate private session-handle */	CALL_OCI_RETURN(OCI(error), OCIHandleAlloc(				session->pEnv, 				(dvoid **)&session->pSession, 				OCI_HTYPE_SESSION, 				0, 				NULL));	if (OCI(error) != OCI_SUCCESS) {		oci_error(OCI(pError), "_oci_open_session: OCIHandleAlloc OCI_HTYPE_SESSION", OCI(error));		goto CLEANUP;	}	/* Set the server handle in service handle */ 	CALL_OCI_RETURN(OCI(error), OCIAttrSet(				svchp, 				OCI_HTYPE_SVCCTX, 				server->pServer, 				0,				OCI_ATTR_SERVER,				OCI(pError)));	if (OCI(error) != OCI_SUCCESS) {		oci_error(OCI(pError), "_oci_open_session: OCIAttrSet OCI_ATTR_SERVER", OCI(error));		goto CLEANUP;	}	/* set the username in user handle */	CALL_OCI_RETURN(OCI(error), OCIAttrSet(				(dvoid *) session->pSession, 				(ub4) OCI_HTYPE_SESSION, 				(dvoid *) username, 				(ub4) strlen(username), 				(ub4) OCI_ATTR_USERNAME, 				OCI(pError)));	if (OCI(error) != OCI_SUCCESS) {		oci_error(OCI(pError), "OCIAttrSet OCI_ATTR_USERNAME", OCI(error));		goto CLEANUP;	}	/* set the password in user handle */	CALL_OCI_RETURN(OCI(error), OCIAttrSet(				(dvoid *) session->pSession, 				(ub4) OCI_HTYPE_SESSION, 				(dvoid *) password, 				(ub4) strlen(password), 				(ub4) OCI_ATTR_PASSWORD, 				OCI(pError)));	if (OCI(error) != OCI_SUCCESS) {		oci_error(OCI(pError), "OCIAttrSet OCI_ATTR_PASSWORD", OCI(error));		goto CLEANUP;	}	CALL_OCI_RETURN(OCI(error), OCISessionBegin(				svchp, 				OCI(pError), 				session->pSession, 				(ub4) OCI_CRED_RDBMS, 				(ub4) OCI_DEFAULT));	if (OCI(error) != OCI_SUCCESS) {		oci_error(OCI(pError), "OCISessionBegin", OCI(error));		/* OCISessionBegin returns OCI_SUCCESS_WITH_INFO when		 * user's password has expired, but is still usable.		 * */		if (OCI(error) != OCI_SUCCESS_WITH_INFO) {			goto CLEANUP;		}	}	/* Free Temporary Service Context */	CALL_OCI(OCIHandleFree(				(dvoid *) svchp, 				(ub4) OCI_HTYPE_SVCCTX));	if (exclusive) {		psession = session;	} else {		zend_hash_update(OCI(user),						 session->hashed_details,						 strlen(session->hashed_details)+1, 						 (void *)session,						 sizeof(oci_session),						 (void**)&psession);	}	psession->num = zend_list_insert(psession,le_session); 	psession->is_open = 1;	oci_debug("_oci_open_session new sess=%d user=%s",psession->num,username);	if (! exclusive) free(session);	return psession;CLEANUP:	oci_debug("_oci_open_session: FAILURE -> CLEANUP called");	_oci_close_session(session);	return 0;}/* }}} *//* {{{ _oci_close_session() */static void_oci_close_session(oci_session *session){	OCISvcCtx *svchp;	char *hashed_details;	TSRMLS_FETCH();	if (! session) {		return;	}	oci_debug("START _oci_close_session: logging-off sess=%d",session->num);	if (session->is_open) {		/* Temporary Service Context */		CALL_OCI_RETURN(OCI(error), OCIHandleAlloc(					session->pEnv, 					(dvoid **) &svchp, 					(ub4) OCI_HTYPE_SVCCTX, 					(size_t) 0, 					(dvoid **) 0));				if (OCI(error) != OCI_SUCCESS) {			oci_error(OCI(pError), "_oci_close_session OCIHandleAlloc OCI_HTYPE_SVCCTX", OCI(error));		}				/* Set the server handle in service handle */ 		CALL_OCI_RETURN(OCI(error), OCIAttrSet(					svchp, 					OCI_HTYPE_SVCCTX, 					session->server->pServer, 					0, 					OCI_ATTR_SERVER, 					OCI(pError)));		if (OCI(error) != OCI_SUCCESS) {			oci_error(OCI(pError), "_oci_close_session: OCIAttrSet OCI_ATTR_SERVER", OCI(error));		}				/* Set the Authentication handle in the service handle */		CALL_OCI_RETURN(OCI(error), OCIAttrSet(					svchp, 						OCI_HTYPE_SVCCTX, 					session->pSession, 					0, 					OCI_ATTR_SESSION, 					OCI(pError)));		if (OCI(error) != OCI_SUCCESS) {			oci_error(OCI(pError), "_oci_close_session: OCIAttrSet OCI_ATTR_SESSION", OCI(error));		}			CALL_OCI_RETURN(OCI(error), OCISessionEnd(					svchp, 					OCI(pError), 					session->pSession, 					(ub4) 0));		if (OCI(error) != OCI_SUCCESS) {			oci_error(OCI(pError), "_oci_close_session: OCISessionEnd", OCI(error));		}		C

⌨️ 快捷键说明

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