Пример #1
0
////////////////////////////////////////////
// get the name of a SQL object id in 
// Unicode.
////////////////////////////////////////////
SQLCLI_LIB_FUNC
NAWchar* getIdInWchar(SQLCLI_OBJ_ID* x)
{
   static NAWcharBuf * buf = new NAWcharBuf(MAX_CHAR_SET_STRING_LENGTH+1);

   if ( x == 0 ) return 0;

   const char* charset = getIdCharSet(x);
   NAWcharBuf* res = 0;

   if ( charset == SQLCHARSETSTRING_UNICODE || str_cmp(charset, SQLCHARSETSTRING_UNICODE,str_len(charset)) == 0 ) {
     return (NAWchar*)(x -> identifier);
   }
   if ( charset == SQLCHARSETSTRING_ISO88591 || str_cmp(charset, SQLCHARSETSTRING_ISO88591,str_len(charset)) == 0 ) {
     res = ISO88591ToUnicode(
	charBuf((unsigned char*)(x->identifier), getIdLen(x)), 
	(CollHeap *)0,
	buf
		      );
     return (res) ? (res -> data()) : 0;
   }
   return 0;
}
Пример #2
0
////////////////////////////////////////////
// get the name of a SQL module id in 
// Unicode.
////////////////////////////////////////////
SQLCLI_LIB_FUNC
NAWchar* getModNameInWchar(const SQLMODULE_ID* m)
{
   static NAWcharBuf * buf = new NAWcharBuf(MAX_CHAR_SET_STRING_LENGTH+1);

   if ( m == 0 ) return 0;

   const char* charset = getModCharSet(m);
   NAWcharBuf* res = 0;

   if ( charset == SQLCHARSETSTRING_UNICODE || str_cmp(charset, SQLCHARSETSTRING_UNICODE,str_len(charset)) == 0 ) {
     return (NAWchar*)(m -> module_name);
   }
   if ( charset == SQLCHARSETSTRING_ISO88591 || str_cmp(charset, SQLCHARSETSTRING_ISO88591,str_len(charset)) == 0 ) {
     res = ISO88591ToUnicode(
	charBuf((unsigned char*)(m->module_name), getModNameLen(m)), 
	(CollHeap *)0,
	buf
		      );
     return (res) ? (res -> data()) : 0;
   }
   return 0;
}
Lng32 
LocaleStringToUnicode(Lng32 charset, const char* str, Lng32 strLen, 
                      NAWchar* wstrBuf, Lng32 wstrBufLen, NABoolean addNullAtEnd)
{
   // Changed the algorithm to call the new LocaleToUTF16() but keep
   // the old call to old ISO88591ToUnicode() when the character set is
   // ISO88591.  We want to keep the old "pass through" behavior so
   // Use of ISO 8859-15 characters (a.k.a., Latin-9) in
   // CHARACTER SET ISO88591 target column continues to work.

   if (charset == (Lng32) CharInfo::ISO88591)
   {
     NAWcharBuf wcbuf(wstrBuf, wstrBufLen);
     NAWcharBuf* wcbufPtr = &wcbuf;
     NAWcharBuf* res = 0;
     res = ISO88591ToUnicode(
                charBuf((unsigned char*)str, strLen), 0,
                wcbufPtr, addNullAtEnd
                        );
     return (res) ? res->getStrLen() : 0;
   }

   //
   // else (charset != (Lng32) CharInfo::ISO88591)
   //

   enum cnv_charset convCS = convertCharsetEnum(charset);
   if (convCS == cnv_UnknownCharSet)
     return 0; // nothing we can do; exit the routine

   UInt32 outBufSizeInBytes = wstrBufLen*sizeof(NAWchar);
   char * pFirstUntranslatedChar = NULL;
   UInt32 outputDataLenInBytes = 0;
   UInt32 translatedtCharCount = 0;
   Int32 convStatus =
     LocaleToUTF16(cnv_version1,           // const enum cnv_version version
                   str,                    // const char *in_bufr
                   strLen,                 // const int in_len in # of bytes
                   (const char *)wstrBuf,  // const char *out_bufr
                   (const Int32)outBufSizeInBytes,
                   convCS,       // enum cnv_charset charset -- output charset
                   pFirstUntranslatedChar, // char * & first_untranslated_char
                   &outputDataLenInBytes,  // unsigned int *output_data_len_p
                   0,                      // const int cnv_flags (default is 0)
                   (const Int32)addNullAtEnd,
                   &translatedtCharCount); // unsigned int *translated_char_cnt_p

   UInt32 outLenInW = outputDataLenInBytes/sizeof(NAWchar);
   if (convStatus == 0) // success
     return outLenInW;  // include the NULL terminator if (addNullAtEnd == TRUE)

   // If convStatus != 0, LocaleToUTF16 will not add the NULL terminator
   if (addNullAtEnd && wstrBuf && wstrBufLen > 0)
   {
     if (outLenInW < (UInt32)wstrBufLen)
       wstrBuf[outLenInW] = WIDE_('\0');
     else
     {
       // assume the specified wstrBufLen includes room for the NULL terminator
       // when the passed-in addNullAtEnd parameter is set to TRUE
       wstrBuf[wstrBufLen-1] = WIDE_('\0');
     }
   }
   return 0; // tell the caller not to use data in wstrBuf
}
Пример #4
0
void AioFile::open(StringRef fileName, OpenMode_Enum mode, int permissions)
{
    // TODO: Properly convert filename
    size_t fileNameLen = fileName.length();

    ShortList<char, 256> charBuf(fileNameLen+1);

    charBuf.addBlockBack(fileName.data(), fileNameLen);
    charBuf.addBack('\0');

    // Don't inherit any fd
    int flags = O_CLOEXEC;

    // Build permission flags
    // It's legal, if normally pointless, to have no read or write access.
    // You can still access the file length.
    if ((permissions & IO_READ_ACCESS) &&
        (permissions & IO_WRITE_ACCESS))
    {
        flags |= O_RDWR;
    }
    else if (permissions & IO_READ_ACCESS)
    {
        flags |= O_WRONLY;
    }
    else if (permissions & IO_WRITE_ACCESS)
    {
        flags |= O_RDONLY;
    }

    // Build file creation flags
    switch (mode)
    {
    case OPEN_MODE_CREATE_ONLY:
        flags |= O_CREAT;
        flags |= O_EXCL;
        break;
    case OPEN_MODE_CREATE_OR_OPEN:
        flags |= O_CREAT;
        break;
    case OPEN_MODE_CREATE_OR_TRUNCATE:
        flags |= O_CREAT;
        flags |= O_TRUNC;
        break;
    case OPEN_MODE_OPEN_ONLY:
        // No extra flags
        break;
    case OPEN_MODE_TRUNCATE_ONLY:
        flags |= O_TRUNC;
        break;
    }

    _fd = UnixUtil::sys_open(charBuf.data(), flags, 0666);

    if (_fd == -1)
    {
        Error error = UnixUtil::getError(errno,
                                         "open",
                                         "AioFile::open");
        throw IOException(error);
    }
}