예제 #1
0
void veroMakeUriTest() {
	char project[100];

	strcpy(project, "yulins_project");
	makeSlug(project);
	
	cout << "\n";
	cout << "Project make slug = " << project << "\n";

	std::wstringstream metaUri = makeMetaUri(project);
	std::wstringstream queryUri = makeQueryUri(project);

	std::unique_ptr<char[]> metaUriPtr = wchar2char(metaUri.str().c_str());
	std::unique_ptr<char[]> queryUriPtr = wchar2char(queryUri.str().c_str());

	cout << "Meta uri = " << metaUriPtr.get() << "\n";
	cout << "Query uri = " << queryUriPtr.get() << "\n";
}
예제 #2
0
//-------------------------------------------------------------------------------------
void SpaceAvatarSelect::kbengine_onEvent(const KBEngine::EventData* lpEventData)
{
	switch(lpEventData->id)
	{
		case CLIENT_EVENT_SCRIPT:
			{
				const KBEngine::EventData_Script* peventdata = static_cast<const KBEngine::EventData_Script*>(lpEventData);
				if(peventdata->name == "update_avatars")
				{
					if(peventdata->argsSize > 0)
					{
						PyObject* pyitem = PyTuple_GetItem(peventdata->pyDatas, 0);
						for(KBEngine::uint32 i=0; i<g_avatars.size(); i++)
						{
							mTrayMgr->destroyWidget(g_avatars[i]);
						}
						
						g_avatars.clear();

						PyObject *key, *value;
						Py_ssize_t pos = 0;
						while (PyDict_Next(pyitem, &pos, &key, &value)) 
						{
							wchar_t* PyUnicode_AsWideCharStringRet0 = PyUnicode_AsWideCharString(PyDict_GetItemString(value, "name"), NULL);
							char* name = wchar2char(PyUnicode_AsWideCharStringRet0);
							PyMem_Free(PyUnicode_AsWideCharStringRet0);
							
							KBEngine::DBID dbid = 0;
							dbid = PyLong_AsUnsignedLongLong(key);
 							if (PyErr_Occurred())																	
 							{																						
								dbid = PyLong_AsUnsignedLong(key);														
							}	
 							if (PyErr_Occurred())																	
 							{																						
								PyErr_PrintEx(0);																	
							}	

							Ogre::String str = Ogre::String(name) + "_" + KBEngine::StringConv::val2str(dbid);
							g_avatars.push_back(str);
							mTrayMgr->createButton(OgreBites::TL_CENTER, str, str, 300);

							free(name);
						}																					
					}
				}
			}
			break;
		default:
			break;
	};
}
예제 #3
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
std::vector<std::string> XGDI::listEncoders( void ) const
{
	std::vector<std::string> enc;
	char	*name = NULL;
	int	i;
	for( i = 0; i < (int) ncodec_info; i++ )
		{
		name = wchar2char( codec_info[i].MimeType );
		if ( NULL != name )
			{enc.push_back( std::string(name) );
			free( name );
			name = NULL;
			}
		else
			{enc.push_back( "?unknown" );
			}
		}
	return( enc );
}
예제 #4
0
// -----------------------------------------------------------------------
// to connect to the driver
// -----------------------------------------------------------------------
RETCODE SQL_API SQLDriverConnectW ( SQLHDBC            hdbc,
                                    SQLHWND             hwnd,
                                    SQLWCHAR*           szConnStrIn,
                                    SQLSMALLINT         cchConnStrIn,
                                    SQLWCHAR*           szConnStrOut,
                                    SQLSMALLINT         cchConnStrOutMax,
                                    SQLSMALLINT*        pcchConnStrOut,
                                    SQLUSMALLINT        fDriverCompletion ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "SQLDriverConnectW called, cchConnStrIn %d, cchConnStrOutMax %d, wcslen %d",
                              cchConnStrIn, cchConnStrOutMax, wcslen ( szConnStrIn ) ) );
    int inStrLength = wcslen ( szConnStrIn ) + 1;
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The inStr Length is : %d", inStrLength ) );
    unique_ptr<char[]> pInStr ( new char[inStrLength] );
    unique_ptr<char[]> pOutStr ( new char[cchConnStrOutMax + 1] );
    wchar2char ( szConnStrIn, pInStr.get(), inStrLength );
    //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG,"The inStr is : %s",pInStr.get()));
    SQLSMALLINT outStrLength = 0 ;
    RETCODE code = SQLDriverConnect ( hdbc, hwnd, ( SQLCHAR* ) pInStr.get(), cchConnStrIn, ( SQLCHAR* ) pOutStr.get(),
                                      cchConnStrOutMax, &outStrLength, fDriverCompletion );
                                      
    if ( code == SQL_ERROR ) {
        return code;
    }
    
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "pcchConnStrOut null? %d, cchConnStrOutMax > 0 ? %d, szConnStrOut null? %d",
                              pcchConnStrOut == NULL, cchConnStrOutMax > 0 , szConnStrOut == NULL ) );
                              
    if ( cchConnStrOutMax > 0 && pcchConnStrOut && szConnStrOut ) {
        char2wchar ( pOutStr.get(), szConnStrOut, ( int ) cchConnStrOutMax );
        *pcchConnStrOut = wcslen ( szConnStrOut );
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "(W)The Length of Out Conn Str is %d", *pcchConnStrOut ) );
    }
    
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "the ret code is %d", code ) );
    return code;
}
예제 #5
0
/*
 * Convert a Windows setlocale() argument to a Unix-style one.
 *
 * Regardless of platform, we install message catalogs under a Unix-style
 * LL[_CC][.ENCODING][@VARIANT] naming convention.	Only LC_MESSAGES settings
 * following that style will elicit localized interface strings.
 *
 * Before Visual Studio 2012 (msvcr110.dll), Windows setlocale() accepted "C"
 * (but not "c") and strings of the form <Language>[_<Country>][.<CodePage>],
 * case-insensitive.  setlocale() returns the fully-qualified form; for
 * example, setlocale("thaI") returns "Thai_Thailand.874".	Internally,
 * setlocale() and _create_locale() select a "locale identifier"[1] and store
 * it in an undocumented _locale_t field.  From that LCID, we can retrieve the
 * ISO 639 language and the ISO 3166 country.  Character encoding does not
 * matter, because the server and client encodings govern that.
 *
 * Windows Vista introduced the "locale name" concept[2], closely following
 * RFC 4646.  Locale identifiers are now deprecated.  Starting with Visual
 * Studio 2012, setlocale() accepts locale names in addition to the strings it
 * accepted historically.  It does not standardize them; setlocale("Th-tH")
 * returns "Th-tH".  setlocale(category, "") still returns a traditional
 * string.	Furthermore, msvcr110.dll changed the undocumented _locale_t
 * content to carry locale names instead of locale identifiers.
 *
 * MinGW headers declare _create_locale(), but msvcrt.dll lacks that symbol.
 * IsoLocaleName() always fails in a MinGW-built postgres.exe, so only
 * Unix-style values of the lc_messages GUC can elicit localized messages.	In
 * particular, every lc_messages setting that initdb can select automatically
 * will yield only C-locale messages.  XXX This could be fixed by running the
 * fully-qualified locale name through a lookup table.
 *
 * This function returns a pointer to a static buffer bearing the converted
 * name or NULL if conversion fails.
 *
 * [1] http://msdn.microsoft.com/en-us/library/windows/desktop/dd373763.aspx
 * [2] http://msdn.microsoft.com/en-us/library/windows/desktop/dd373814.aspx
 */
static char *
IsoLocaleName(const char *winlocname)
{
#if (_MSC_VER >= 1400)			/* VC8.0 or later */
	static char iso_lc_messages[32];
	_locale_t	loct = NULL;

	if (pg_strcasecmp("c", winlocname) == 0 ||
		pg_strcasecmp("posix", winlocname) == 0)
	{
		strcpy(iso_lc_messages, "C");
		return iso_lc_messages;
	}

	loct = _create_locale(LC_CTYPE, winlocname);
	if (loct != NULL)
	{
#if (_MSC_VER >= 1700)			/* Visual Studio 2012 or later */
		size_t		rc;
		char	   *hyphen;

		/* Locale names use only ASCII, any conversion locale suffices. */
		rc = wchar2char(iso_lc_messages, loct->locinfo->locale_name[LC_CTYPE],
						sizeof(iso_lc_messages), NULL);
		_free_locale(loct);
		if (rc == -1 || rc == sizeof(iso_lc_messages))
			return NULL;

		/*
		 * Since the message catalogs sit on a case-insensitive filesystem, we
		 * need not standardize letter case here.  So long as we do not ship
		 * message catalogs for which it would matter, we also need not
		 * translate the script/variant portion, e.g. uz-Cyrl-UZ to
		 * uz_UZ@cyrillic.	Simply replace the hyphen with an underscore.
		 *
		 * Note that the locale name can be less-specific than the value we
		 * would derive under earlier Visual Studio releases.  For example,
		 * French_France.1252 yields just "fr".  This does not affect any of
		 * the country-specific message catalogs available as of this writing
		 * (pt_BR, zh_CN, zh_TW).
		 */
		hyphen = strchr(iso_lc_messages, '-');
		if (hyphen)
			*hyphen = '_';
#else
		char		isolang[32],
					isocrty[32];
		LCID		lcid;

		lcid = loct->locinfo->lc_handle[LC_CTYPE];
		if (lcid == 0)
			lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
		_free_locale(loct);

		if (!GetLocaleInfoA(lcid, LOCALE_SISO639LANGNAME, isolang, sizeof(isolang)))
			return NULL;
		if (!GetLocaleInfoA(lcid, LOCALE_SISO3166CTRYNAME, isocrty, sizeof(isocrty)))
			return NULL;
		snprintf(iso_lc_messages, sizeof(iso_lc_messages) - 1, "%s_%s", isolang, isocrty);
#endif
		return iso_lc_messages;
	}
	return NULL;
#else
	return NULL;				/* Not supported on this version of msvc/mingw */
#endif   /* _MSC_VER >= 1400 */
}
예제 #6
0
// --------------------------------------------------------------------
// log a specified message
// --------------------------------------------------------------------
void _ODBCLogMsg ( LogLevel level , const wchar_t* textW ) {
    unique_ptr<char[]> p ( wchar2char ( textW ) );
    _ODBCLogMsg ( level, p.get() );
}
예제 #7
0
RETCODE SQL_API SQLGetDiagField ( SQLSMALLINT     pHandleType,
                                  SQLHANDLE       pHandle,
                                  SQLSMALLINT     pRecNum,
                                  SQLSMALLINT     pFldID,
                                  SQLPOINTER      pDataPtr,
                                  SQLSMALLINT     pDataSize,
                                  SQLSMALLINT*    pDataSizePtr ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG,
                              "SQLGetDiagField called, HandleType: %d, RecNum: %d, InfoType: %d, BufLen: %d", pHandleType, pRecNum, pFldID,
                              pDataSize ) );
    bool            c;
    pODBCDiag    diag;
    pODBCDiagRow diagrow;
    SQLSMALLINT dummySize = 0;//used when pDataSizePtr is NULL
    
    if ( pDataSizePtr == NULL )
    { pDataSizePtr = &dummySize; }
    
    __CHK_HANDLE ( pHandle, pHandleType, SQL_ERROR );
    diag = _SQLGetDiagHandle ( pHandleType, pHandle );
    
    if ( !diag ) { return SQL_ERROR; }
    
    // field may be in diag header
    c = FALSE;
    
    // check the field type - header fields
    switch ( pFldID ) {
        case SQL_DIAG_CURSOR_ROW_COUNT:
        case SQL_DIAG_ROW_COUNT:                            // rows affected by update/insert
            if ( pHandleType == SQL_HANDLE_STMT ) {
                if ( pDataPtr )
                { * ( ( SQLLEN* ) pDataPtr ) = ( pHandle ) ? ( ( pODBCStmt ) pHandle )->RowCount : 0; }
                
                return SQL_SUCCESS;
            }
            
            else
            { return SQL_ERROR; }
            
        case SQL_DIAG_DYNAMIC_FUNCTION:
            if ( pHandleType == SQL_HANDLE_STMT ) {
                unique_ptr<char[]> p ( wchar2char ( ( ( pODBCStmt ) pHandle )->Stmt ) );
                _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, p.get(), ( ( pODBCStmt ) pHandle )->StmtLen );
                return SQL_SUCCESS;
            }
            
            else
            { return SQL_ERROR; }
            
            return SQL_ERROR;
            
        case SQL_DIAG_DYNAMIC_FUNCTION_CODE:
            if ( pHandleType == SQL_HANDLE_STMT ) {
                if ( pDataPtr )
                { * ( ( StrPtr ) pDataPtr ) = 1; }          // ??? debug test only
                
                unique_ptr<char[]> p ( wchar2char ( ( ( pODBCStmt ) pHandle )->Stmt ) );
                _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, p.get(), ( ( ( pODBCStmt ) pHandle )->StmtLen ) );
                return SQL_SUCCESS;
            }
            
            else
            { return SQL_ERROR; }
            
        case SQL_DIAG_NUMBER: {                             // number of rows in diag
                Word i;
                
                // check if there r any diag rows
                if ( diag->DiagRows ) {
                    // loop to count the rows
                    for ( i = 1, diagrow = diag->DiagRows; diagrow != NULL; diagrow = diagrow->Next, i ++ );
                    
                    if ( pDataPtr )  { * ( ( Word* ) pDataPtr ) = i; }
                }
                
                else if ( pDataPtr )  { * ( ( Word* ) pDataPtr ) = 0; }
                
                return SQL_SUCCESS;
            }
            break;
            
        default:
            c = TRUE;
    }
    
    // check if only a header field was required
    if ( c == FALSE )
    { return SQL_SUCCESS; }
    
    // check row and buffer
    if ( pRecNum <= 0 || pDataSize < 0 ) {
        __ODBCPOPMSG ( _ODBCPopMsg ( "GetDiagField  xxx1" ) );
        return SQL_ERROR;
    }
    
    // now get the desired row first
    if ( ( diagrow = _SQLGetDiagRowX ( diag, pRecNum ) ) == NULL )
    { return SQL_NO_DATA; }
    
    // now set info as per the field required
    switch ( pFldID ) {
        case SQL_DIAG_CLASS_ORIGIN:
            _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, "ODBC 3.0", -1 );
            break;
            
        case SQL_DIAG_COLUMN_NUMBER:
        
            // needs to be implemented
            if ( pDataPtr )  { * ( ( Long* ) pDataPtr ) = diagrow->Col; }
            
            break;
            
        case SQL_DIAG_CONNECTION_NAME:
            if ( pDataPtr )             { * ( ( char* ) pDataPtr ) = 0; }
            
            if ( pDataSizePtr )         { *pDataSizePtr   = 0; }
            
            break;
            
        case SQL_DIAG_MESSAGE_TEXT:
            return _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, diagrow->Msg, -1 );
            
        case SQL_DIAG_NATIVE:
            if ( pDataPtr )             { * ( ( Long* ) pDataPtr ) = diagrow->NativeErrorCode; }
            
            if ( pDataSizePtr )         { *pDataSizePtr   = 0; }
            
            break;
            
        case SQL_DIAG_ROW_NUMBER:
        
            // needs to be implemented
            if ( pDataPtr )  { * ( ( Long* ) pDataPtr ) = diagrow->Row; }
            
            break;
            
        case SQL_DIAG_SERVER_NAME: {
                CStrPtr svr;
                
                // if handle type is connection
                if ( pHandleType  == SQL_HANDLE_DBC )
                { svr = ( ( pODBCConn ) pHandle )->Server; }
                
                else if ( pHandleType == SQL_HANDLE_STMT && ( ( pODBCStmt ) pHandle )->Conn )
                { svr = ( ( pODBCStmt ) pHandle )->Conn->Server; }
                
                else
                { svr = ""; }
                
                return _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, svr, -1 );
            }
            
        case SQL_DIAG_SQLSTATE:
            return _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, diagrow->State, -1 );
            
        case SQL_DIAG_SUBCLASS_ORIGIN:
            // ??? dummy
            return _SQLCopyCharData ( diag, pDataPtr, pDataSize, pDataSizePtr, 16, diagrow->State, -1 );
            
        default:
            __ODBCPOPMSG ( _ODBCPopMsg ( "SQLGetDiagField called, HandleType: %d, RecNum: %d, InfoType: %d, BufLen: %d",
                                         pHandleType, pRecNum, pFldID, pDataSize ) );
            return SQL_ERROR;
    }
    
    return SQL_SUCCESS;
}
예제 #8
0
파일: ts_locale.c 프로젝트: 0x0FFF/postgres
/*
 * lowerstr_with_len --- fold string to lower case
 *
 * Input string need not be null-terminated.
 *
 * Returned string is palloc'd
 */
char *
lowerstr_with_len(const char *str, int len)
{
	char	   *out;

#ifdef USE_WIDE_UPPER_LOWER
	Oid			collation = DEFAULT_COLLATION_OID;		/* TODO */
	pg_locale_t mylocale = 0;	/* TODO */
#endif

	if (len == 0)
		return pstrdup("");

#ifdef USE_WIDE_UPPER_LOWER

	/*
	 * Use wide char code only when max encoding length > 1 and ctype != C.
	 * Some operating systems fail with multi-byte encodings and a C locale.
	 * Also, for a C locale there is no need to process as multibyte. From
	 * backend/utils/adt/oracle_compat.c Teodor
	 */
	if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c(collation))
	{
		wchar_t    *wstr,
				   *wptr;
		int			wlen;

		/*
		 * alloc number of wchar_t for worst case, len contains number of
		 * bytes >= number of characters and alloc 1 wchar_t for 0, because
		 * wchar2char wants zero-terminated string
		 */
		wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len + 1));

		wlen = char2wchar(wstr, len + 1, str, len, mylocale);
		Assert(wlen <= len);

		while (*wptr)
		{
			*wptr = towlower((wint_t) *wptr);
			wptr++;
		}

		/*
		 * Alloc result string for worst case + '\0'
		 */
		len = pg_database_encoding_max_length() * wlen + 1;
		out = (char *) palloc(len);

		wlen = wchar2char(out, wstr, len, mylocale);

		pfree(wstr);

		if (wlen < 0)
			ereport(ERROR,
					(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
			errmsg("conversion from wchar_t to server encoding failed: %m")));
		Assert(wlen < len);
	}
	else
#endif   /* USE_WIDE_UPPER_LOWER */
	{
		const char *ptr = str;
		char	   *outptr;

		outptr = out = (char *) palloc(sizeof(char) * (len + 1));
		while ((ptr - str) < len && *ptr)
		{
			*outptr++ = tolower(TOUCHAR(ptr));
			ptr++;
		}
		*outptr = '\0';
	}

	return out;
}
예제 #9
0
//mhb TODO, check if the sqltype defined here match from c#
RETCODE SQL_API _SQLColConvert ( pODBCStmt       pStmt,
                                 void*               pTgtDataPtr,
                                 Long*               pTgtDataSizePtr,
                                 const wchar_t*      pSrcColData,
                                 pARDItem     pARDCol,
                                 bool                isSigned ) {
    //check out this for SQL data type to C data type mapping
    //http://msdn.microsoft.com/en-us/library/ms714556(v=vs.85).aspx
    // note
    // this function actually determines the conversion
    // required to transfer the data
    Word    pSrcDataType = pARDCol->SrcDataType;
    Word    pTgtDataType = pARDCol->DataConciseType;
    Long    pTgtDataSize = pARDCol->DataSize;
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "_SQLColConvert called" ) );
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "The SrcDataType is %d, the TgtDataType is %d, the TgtDataSize is %d",
                              pSrcDataType, pTgtDataType, pTgtDataSize ) );
                              
    // TARGET TYPE IS LEFT TO OUR DRIVER
    // check if target type is open
    if ( pTgtDataType == SQL_DEFAULT ) {
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "pTgtDataType is SQL_DEFAULT, use default type mapping." ) );
        
        // determine targettype based on data-source type
        // check out this http://msdn.microsoft.com/en-us/library/ms716298(v=vs.85).aspx for default type mapping
        switch ( pSrcDataType ) {
            case SQL_CHAR:
                pTgtDataType = SQL_C_CHAR;
                break;
                
            case SQL_VARCHAR:
                pTgtDataType = SQL_C_CHAR;
                break;
                
            case SQL_WCHAR:
                pTgtDataType = SQL_C_WCHAR;
                break;
                
            case SQL_WVARCHAR:
                pTgtDataType = SQL_C_WCHAR;
                break;
                
            case SQL_DECIMAL:
                pTgtDataType = SQL_C_CHAR;
                break;
                
            case SQL_BIT:
                pTgtDataType = SQL_C_BIT;
                break;
                
            case SQL_TINYINT:
                if ( isSigned )
                { pTgtDataType = SQL_C_STINYINT; }
                
                else
                { pTgtDataType = SQL_C_UTINYINT; }
                
                break;
                
            case SQL_SMALLINT:
                if ( isSigned )
                { pTgtDataType = SQL_C_SSHORT; }
                
                else
                { pTgtDataType = SQL_C_USHORT; }
                
                break;
                
            case SQL_INTEGER:
                if ( isSigned )
                { pTgtDataType = SQL_C_SLONG; }
                
                else
                { pTgtDataType = SQL_C_ULONG; }
                
                break;
                
            case SQL_BIGINT:
                if ( isSigned )
                { pTgtDataType = SQL_C_SBIGINT; }
                
                else
                { pTgtDataType = SQL_C_UBIGINT; }
                
                break;
                
            case SQL_FLOAT:
                pTgtDataType = SQL_C_FLOAT;
                break;
                
            case SQL_DOUBLE:
                pTgtDataType = SQL_C_DOUBLE;
                break;
                
            case SQL_TYPE_DATE:
                pTgtDataType = SQL_C_CHAR;
                break;
                
            case SQL_TYPE_TIME:
                pTgtDataType = SQL_C_CHAR;
                break;
                
            case SQL_TYPE_TIMESTAMP:
                pTgtDataType = SQL_C_CHAR;
                break;
                
            //case SQL_C_SLONG:
            //case SQL_C_ULONG:               // unsigned long
            //case SQL_C_USHORT:
            //case SQL_C_SSHORT:
            //case SQL_NUMERIC:
            //case SQL_REAL:
            //  pTgtDataType = pSrcDataType;
            //  break;
            
            default:
                __ODBCPOPMSG ( _ODBCPopMsg ( "The data type %d not implemented", pSrcDataType ) );
                return SQL_ERROR;
                break;
        }
    }
    
    else {
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "pTgtDataType is NOT SQL_DEFAULT, it is %d",  pTgtDataType ) );
    }
    
    // TARGET TYPE IS CHAR
    // as an optimization, check if the application
    // or target data type is char. since the data from
    // server is already in char format. the data can
    // easily be transferred without incurring any
    // conversion overhead
    unique_ptr<char[]> pTextInAnsi ( wchar2char ( pSrcColData ) );
    
    // check if char type
    if ( pTgtDataType == SQL_CHAR || pTgtDataType == SQL_VARCHAR ) {
        // only in case of src data being bool a conversion is required
        if ( pSrcDataType == SQL_BIT ) {
            // prepare a converted single char bool string
            Char  src[2];
            
            if ( pTextInAnsi.get() == NULL )
            { src[0] = '0'; }
            
            else
            { src[0] = ( pTextInAnsi.get() [0] == 'T' || pTextInAnsi.get() [0] == '1' || pTextInAnsi.get() [0] == 't' ) ? '1' : '0'; }
            
            src[1] = 0;
            // transfer the bool string
            return _SQLCopyCharData ( _DIAGSTMT ( pStmt ), pTgtDataPtr, pARDCol->DataSize, pTgtDataSizePtr, 32, src, -1 );
        }
        
        else {
            // transfer the string as it is
            return _SQLCopyCharData ( _DIAGSTMT ( pStmt ), pTgtDataPtr, pARDCol->DataSize, pTgtDataSizePtr, 32, pTextInAnsi.get(),
                                      -1 );
        }
    }
    
    if ( pTgtDataType == SQL_WCHAR || pTgtDataType == SQL_WVARCHAR ) {
        return _SQLCopyWCharDataW ( _DIAGSTMT ( pStmt ), pTgtDataPtr, pARDCol->DataSize, pTgtDataSizePtr, 32, pSrcColData, -1 );
    }
    
    // TARGET TYPE IS NOT CHAR
    
    // try using a numeric conversion
    switch ( _SQLCopyNumData ( _DIAGSTMT ( pStmt ), pTgtDataPtr, pTgtDataType, pTextInAnsi.get(), pSrcDataType ,
                               pTgtDataSizePtr ) ) {
        case -1:
            return SQL_ERROR;
            
        case 0:
            return SQL_SUCCESS;
            
        default:
            break;
    }
    
    // try using a date/time conversion
    switch ( _SQLCopyDateTimeData ( _DIAGSTMT ( pStmt ), pTgtDataPtr, pTgtDataType, pTextInAnsi.get(), pSrcDataType ) ) {
        case -1:
            return SQL_ERROR;
            
        case 0:
            return SQL_SUCCESS;
            
        default:
            break;
    }
    
    // try using SQL_BIT data type ie bool
    if ( pTgtDataType == SQL_BIT ) {
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "the target data type is SQL_C_BIT" ) );
        
        // prepare a converted single char bool string
        if ( pTextInAnsi.get() == NULL )
        { * ( ( char* ) pTgtDataPtr ) = 0; }
        
        else
        { * ( ( char* ) pTgtDataPtr ) = ( pTextInAnsi.get() [0] == 'T' || pTextInAnsi.get() [0] == '1' || pTextInAnsi.get() [0] == 't' ) ? 1 : 0; }
        
        return SQL_SUCCESS;
    }
    
    // error condition
    __ODBCPOPMSG ( _ODBCPopMsg ( "_SQLColConvert - Unknown data type, Target: %d, Source: %d", pTgtDataType,
                                 pSrcDataType ) );
    _SQLPutDiagRow ( SQL_HANDLE_STMT, pStmt, "_SQLColConvert", "01000", -1, "Unknown data type, Target: %d, Source: %d",
                     pTgtDataType, pSrcDataType );
    return SQL_ERROR;
}
예제 #10
0
//mhb added, for those ard that accept wchar
RETCODE SQL_API _SQLCopyWCharDataW ( pODBCDiag pDiag, void* pTgtDataPtr, Long pDataBufSize, void* pSizePtr,
                                     Word pSizePtrSize, const wchar_t* pSrcData, Long pSrcDataSize ) {
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "_SQLCopyWCharDataW called, pTgtDataPtr is null? %d, pSizePtr == null? %d",
                              pTgtDataPtr == NULL, pSizePtr == NULL ) );
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "_SQLCopyWCharDataW called, the src string is :" ) );
    __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, pSrcData ) );
    Long    n;
    
    // caller safe
    if ( pTgtDataPtr )
    { * ( ( wchar_t* ) pTgtDataPtr ) = 0; }
    
    // DATA SIZE
    
    // check source data to compute size
    if ( pSrcData && _wcsicmp ( pSrcData, L"NULL" ) != 0 )
    { n = ( pSrcDataSize < 0 ) ?  wcslen ( pSrcData ) : pSrcDataSize; }         // compute length based on whether null terminated
    
    else
    { n = 0; }
    
    // check if there is a holder for size
    if ( pSizePtr ) {
        // set size as per ptr type 16-bt or 32-bit
        
        //should be number of characters
        if ( pSizePtrSize == 16 )
        { * ( ( Word* ) pSizePtr ) = ( Word ) ( 2 * n ); }
        
        else
        { * ( ( Long* ) pSizePtr ) = ( 2 * n ); }
        
        __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "pSizePtr is set to %d", n ) );
    }
    
    // check if src data but no size holder
    else if ( pSrcData ) {
        // check if diag to be set
        if ( pDiag )
        { _SQLPutDiagRow ( pDiag, "_SQLCopyWCharDataW", "01000", -1, "No holder for data size", NULL ); }
        
        __ODBCPOPMSG ( _ODBCPopMsg ( "_SQLCopyWCharDataW - No holder for data size" ) );
        return SQL_ERROR;
    }
    
    // DATA
    
    // check if there is a target holder
    if ( pTgtDataPtr ) {
        // check if there is a source pointer
        if ( pSrcData ) {
            // does all of it fit with null char
            if ( pDataBufSize >= ( n + 1 ) ) {
                memcpy ( ( StrPtr ) pTgtDataPtr, pSrcData, 2 * ( n + 1 ) );
                ( ( wchar_t* ) pTgtDataPtr ) [n] = '\0';
                //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG,"_SQLCopyWCharDataW has been called, the target string(not truncated) is :"));
                //unique_ptr<char[]> temp2(wchar2char( (wchar_t*)pTgtDataPtr));
                //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG,temp2.get()));
                return SQL_SUCCESS;
            }
            
            // all of it does not fit
            else {
                //if(pDataBufSize % 2 == 1)
                //  pDataBufSize -= 1;
                memcpy ( ( StrPtr ) pTgtDataPtr, pSrcData, 2 * ( pDataBufSize - 1 ) );
                ( ( wchar_t* ) pTgtDataPtr ) [pDataBufSize - 1] = 0;
                //__ODBCLOG(_ODBCLogMsg(LogLevel_WARN,"_SQLCopyWCharDataW has been called, the target string is(truncated) :"));
                unique_ptr<char[]> temp ( wchar2char ( ( wchar_t* ) pTgtDataPtr ) );
                //__ODBCLOG(_ODBCLogMsg(LogLevel_DEBUG, temp.get()));
                //return SQL_SUCCESS_WITH_INFO may cause error in tableau
                //if ( pDiag )
                //  _SQLPutDiagRow ( pDiag, "_SQLCopyWCharDataW", "01000", -1, "string data truncated", NULL );
                //return SQL_SUCCESS_WITH_INFO;
                __ODBCLOG ( _ODBCLogMsg ( LogLevel_WARN, "string data truncated" ) );
                return SQL_SUCCESS;
            }
        }
        
        // tgt data but no src data
        else {
            // clear tgt
            * ( ( wchar_t* ) pTgtDataPtr ) = 0;
            __ODBCLOG ( _ODBCLogMsg ( LogLevel_DEBUG, "_SQLCopyWCharDataW has been called, the string is (empty) %s",
                                      pTgtDataPtr ) );
        }
    }
    
    return SQL_SUCCESS;
}
예제 #11
0
// 处理GM消息
int CSoMJFrameLogic::ProcessRequestGMCmd(UINT nPlayerID, int nChair, void * pcGameData, UINT nDataLen)
{
    /***************************************************************************************
    * GM换牌操作命令指南:
    * 牌值: 1-9 万(w), 筒(t), 条(t), 东(df), 南(nf), 西(xf), 北(bf), 中(hz), 发(fc), 白(bb), 春(ch), 夏(xh), 秋(qh), 冬(dh), 梅(mh), 兰(lh), 竹(zh), 菊(jh)
    * swap *,1w2w3w4w5w6w7w8w9w1s2s3s4s4s    换牌所有牌命令
    * swap 1w2w3w,1s2s3s                     换手牌现有的牌
    * next 1w1t1s                            下面要摸的牌
    * set 1w2w3w                             自己下面要摸的牌
	* dice 1,6,5,7                           设置游戏接下来的骰子点数, 每次取2个骰子
    ****************************************************************************************/

    if (0 == GetMJSetting().nOpenGM)
    {
        return 1;
    }

    ISoGameProcessor* pProcessor = GetSoGameProcess();
    if (NULL == pProcessor)
    {
        return 1;
    }

    ISoUserManager* pUserMgr = GetSoUserManager();
    if (NULL == pUserMgr)
    {
        return 1;
    }

    TCMD_REQUEST_GMCMD* pCmd = (TCMD_REQUEST_GMCMD*)pcGameData;

    if (NULL == pCmd)
    {
        return 1;
    }

    TCMD_NOTIFY_GMCMD cmd;
    cmd.ucChair = nChair;
    cmd.ucGMCmd = 0;

    char chGMCmd[500 + 1] = {0};
    wchar2char(pCmd->strGMCmd, chGMCmd);
    UINT tempLen = Mystrnlen(chGMCmd, sizeof(chGMCmd));
    if ((tempLen ==0) || (tempLen== sizeof(chGMCmd)))
    {
        return 1;
    }

    char *pData = NULL;
    pData = Mystrstr(chGMCmd, ' ', tempLen);
    if (pData == NULL)
    {
        return 1;
    }
    // 获取关键字命令, 例 swap 1w,3w字符串中获取 swap关键字
    //pKey = strtok(chGMCmd, " ");
    // 获取除去关键字的字符串
    //pData = strtok(NULL, "");

	if (memcmp(GMCMD_SET_DICE, chGMCmd, sizeof(GMCMD_SWAP) - 1) == 0)
	{
		// 进行骰子数设定
		if (TransGMCmdSetDice(nChair, pData))
		{
			_snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d执行更新骰子命令成功", nChair);
		}
		else
		{
			_snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d执行更新骰子命令失败", nChair);
		}
	}
	else if (memcmp(GMCMD_SET_DEALER, chGMCmd, sizeof(GMCMD_SET_DEALER) - 1) == 0)
	{
		// 进行庄家设定
		if (TransGMCmdSetDealer(nChair, pData))
		{
			_snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d执行更新庄家命令成功", nChair);
		}
		else
		{
			_snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d执行更新庄家命令失败", nChair);
		}
	}
    else if (memcmp(GMCMD_SWAP, chGMCmd, sizeof(GMCMD_SWAP) - 1) == 0)
    {
        // 手牌进行换牌
        if (TransGMCmdSwap(nChair, pData))
        {
            _snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d执行换牌命令成功", nChair);
        }
        else
        {
            _snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d执行换牌命令失败", nChair);
        }
    }
    else if (memcmp(GMCMD_NEXT, chGMCmd, sizeof(GMCMD_NEXT) - 1) == 0)
    {
        // 设置下一张抓牌数据
        if (TransGMCmdNext(nChair, pData))
        {
            _snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d设置下一张摸牌数据成攻", nChair);
        }
        else
        {
            _snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d设置下一张摸牌数据失败", nChair);
        }
    }
    else if (memcmp(GMCMD_SET, chGMCmd, sizeof(GMCMD_SET) - 1) == 0)
    {
        // 设置自己接下来要抓的牌数据
        if (TransGMCmdSet(nChair, pData))
        {
            _snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d设置自己接下来要抓的牌数据成攻", nChair);
        }
        else
        {
            _snprintf(cmd.strGMResult, sizeof(cmd.strGMResult), "GMCMD: 玩家%d设置自己接下来要抓的牌数据失败", nChair);
        }
    }

    _DOUT1("\n%s\n", cmd.strGMResult);

    if (m_pSoGameProcessor != NULL)
    { 
        m_pSoGameProcessor->SendGameDataTo(nPlayerID, (char*)&cmd, sizeof(cmd));
    }

    return 0;
}
예제 #12
0
//-------------------------------------------------------------------------------------
bool Script::install(const wchar_t* pythonHomeDir, std::wstring pyPaths, const char* moduleName, COMPONENT_TYPE componentType)
{
	std::wstring pySysPaths = SCRIPT_PATH;
	wchar_t* pwpySysResPath = char2wchar(const_cast<char*>(Resmgr::getPySysResPath().c_str()));
	kbe_replace(pySysPaths, L"../../res/", pwpySysResPath);
	pyPaths += pySysPaths;
	free(pwpySysResPath);

#if KBE_PLATFORM == PLATFORM_WIN32
	Py_SetPythonHome(const_cast<wchar_t*>(pythonHomeDir));								// 先设置python的环境变量
#else
	std::wstring fs = L";";
	std::wstring rs = L":";
	size_t pos = 0; 

	while(true)
	{ 
		pos = pyPaths.find(fs, pos);
		if (pos == std::wstring::npos) break;
		pyPaths.replace(pos, fs.length(), rs);
	}  

	Py_SetPath(pyPaths.c_str()); 
	char* tmpchar = wchar2char(const_cast<wchar_t*>(pyPaths.c_str()));
	DEBUG_MSG("Script::install: paths=%s.\n", tmpchar);
	free(tmpchar);
#endif
	// Initialise python
	// Py_VerboseFlag = 2;
	Py_FrozenFlag = 1;

	// Warn if tab and spaces are mixed in indentation.
	// Py_TabcheckFlag = 1;
	Py_NoSiteFlag = 1;
	Py_IgnoreEnvironmentFlag = 1;
	Py_Initialize();                      												// python解释器的初始化  
    if (!Py_IsInitialized())
    {
    	ERROR_MSG("Script::install::Py_Initialize is failed!\n");
        return false;
    } 

#if KBE_PLATFORM == PLATFORM_WIN32
	PySys_SetPath(pyPaths.c_str());
#endif

	PyObject *m = PyImport_AddModule("__main__");

	module_ = PyImport_AddModule(moduleName);										// 添加一个脚本基础模块
	if (module_ == NULL)
		return false;
	
	const char* componentName = COMPONENT_NAME_EX(componentType);
	if (PyModule_AddStringConstant(module_, "component", componentName))
	{
		ERROR_MSG( "Script::init: Unable to set KBEngine.component to %s\n",
			componentName );
		return false;
	}
	
	// 注册产生uuid方法到py
	APPEND_SCRIPT_MODULE_METHOD(module_,		genUUID64,			__py_genUUID64,					METH_VARARGS,			0);
	
#ifndef KBE_SINGLE_THREADED
	s_pOurInitTimeModules = PyDict_Copy( PySys_GetObject( "modules" ) );
	s_pMainThreadState = PyThreadState_Get();
	s_defaultContext = s_pMainThreadState;
	PyEval_InitThreads();

	KBEConcurrency::setMainThreadIdleFunctions(
		&Script::releaseLock, &Script::acquireLock );
#endif

	ScriptStdOutErr::installScript(NULL);											// 安装py重定向模块
	ScriptStdOutErrHook::installScript(NULL);

	static struct PyModuleDef moduleDesc =   
	{  
			 PyModuleDef_HEAD_INIT,  
			 moduleName,  
			 "This module is created by KBEngine!",  
			 -1,  
			 NULL  
	};  

	PyModule_Create(&moduleDesc);													// 初始化基础模块
	PyObject_SetAttrString(m, moduleName, module_);									// 将模块对象加入main

	pyStdouterr_ = new ScriptStdOutErr();											// 重定向python输出
	pyStdouterrHook_ = new ScriptStdOutErrHook();
	
	if(!pyStdouterr_->install()){													// 安装py重定向脚本模块
		ERROR_MSG("Script::install::pyStdouterr_->install() is failed!\n");
		SCRIPT_ERROR_CHECK();
		return false;
	}
	
	Pickler::initialize();
	Copy::initialize();
	Uuid::initialize();

	math::installModule("Math");
	INFO_MSG("Script::install is successfully!\n");
	return true;
}
예제 #13
0
char *
lowerstr(char *str)
{
	char	   *ptr = str;
	char	   *out;
	int			len = strlen(str);

	if ( len == 0 )
		return pstrdup("");

#ifdef TS_USE_WIDE

	/*
	 * Use wide char code only when max encoding length > 1 and ctype != C.
	 * Some operating systems fail with multi-byte encodings and a C locale.
	 * Also, for a C locale there is no need to process as multibyte. From
	 * backend/utils/adt/oracle_compat.c Teodor
	 */
	if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c())
	{
		wchar_t    *wstr,
				   *wptr;
		int		    wlen;

		/* 
		 *alloc number of wchar_t for worst case, len contains
		 * number of bytes <= number of characters and
		 * alloc 1 wchar_t for 0, because wchar2char(wcstombs in really)
		 * wants zero-terminated string
		 */
		wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len+1));

		/*
		 * str SHOULD be cstring, so wlen contains number
		 * of converted character
		 */
		wlen = char2wchar(wstr, str, len);
		if ( wlen < 0 )
			ereport(ERROR,
					(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
					 errmsg("translation failed from server encoding to wchar_t")));

		Assert(wlen<=len);
		wstr[wlen] = 0;

		while (*wptr)
		{
			*wptr = towlower((wint_t) *wptr);
			wptr++;
		}

		/*
		 * Alloc result string for worst case + '\0'
		 */
		len = sizeof(char)*pg_database_encoding_max_length()*(wlen+1);
		out = (char*)palloc(len);

		/*
		 * wlen now is number of bytes which is always >= number of characters
		 */
		wlen = wchar2char(out, wstr, len);
		pfree(wstr);

		if ( wlen < 0 )
			ereport(ERROR,
					(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
					 errmsg("translation failed from wchar_t to server encoding %d", errno)));
		Assert(wlen<=len);
		out[wlen]='\0';
	}
	else
#endif
	{
		char *outptr;

		outptr = out = (char*)palloc( sizeof(char) * (len+1) );
		while (*ptr)
		{
			*outptr++ = tolower(*(unsigned char *) ptr);
			ptr++;
		}
		*outptr = '\0';
	}

	return out;
}