예제 #1
0
void StringIMPL::Value(wchar_t *target) const
{
	Isolate::Scope isolate_scope(g_CurrentVM);
	HandleScope handle_scope(g_CurrentVM);
	Local<Context> context = v8::Local<v8::Context>::New(g_CurrentVM, g_GlobalContext);
	Context::Scope context_scope(context);

	Local<v8::String> stringValue = Handle<v8::String>::New(g_CurrentVM, persisted_value);

	stringValue->Write((uint16_t *)target);
}
예제 #2
0
jsvalue JsEngine::StringFromV8(Handle<Value> value)
{
    jsvalue v;
    
    Local<String> s = value->ToString();
    v.length = s->Length();
    v.value.str = new uint16_t[v.length+1];
    if (v.value.str != NULL) {
        s->Write(v.value.str);
        v.type = JSVALUE_TYPE_STRING;
    }

    return v;
}   
예제 #3
0
파일: node.cpp 프로젝트: ngocdaothanh/jsg
// Returns number of bytes written.
ssize_t DecodeWrite(char *buf,
                    size_t buflen,
                    Handle<Value> val,
                    enum encoding encoding) {
  HandleScope scope;

  // XXX
  // A lot of improvement can be made here. See:
  // http://code.google.com/p/v8/issues/detail?id=270
  // http://groups.google.com/group/v8-dev/browse_thread/thread/dba28a81d9215291/ece2b50a3b4022c
  // http://groups.google.com/group/v8-users/browse_thread/thread/1f83b0ba1f0a611

  if (val->IsArray()) {
    fprintf(stderr, "'raw' encoding (array of integers) has been removed. "
                    "Use 'binary'.\n");
    assert(0);
    return -1;
  }

  Local<String> str = val->ToString();

  if (encoding == UTF8) {
    str->WriteUtf8(buf, buflen, NULL, String::HINT_MANY_WRITES_EXPECTED);
    return buflen;
  }

  if (encoding == ASCII) {
    str->WriteAscii(buf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);
    return buflen;
  }

  // THIS IS AWFUL!!! FIXME

  assert(encoding == BINARY);

  uint16_t * twobytebuf = new uint16_t[buflen];

  str->Write(twobytebuf, 0, buflen, String::HINT_MANY_WRITES_EXPECTED);

  for (size_t i = 0; i < buflen; i++) {
    unsigned char *b = reinterpret_cast<unsigned char*>(&twobytebuf[i]);
    buf[i] = b[0];
  }

  delete [] twobytebuf;

  return buflen;
}
예제 #4
0
Parameter* ODBC::GetParametersFromArray (Local<Array> values, int *paramCount) {
  DEBUG_PRINTF("ODBC::GetParametersFromArray\n");
  *paramCount = values->Length();
  
  Parameter* params = (Parameter *) malloc(*paramCount * sizeof(Parameter));

  for (int i = 0; i < *paramCount; i++) {
    Local<Value> value = values->Get(i);
    
    params[i].size          = 0;
    params[i].length        = SQL_NULL_DATA;
    params[i].buffer_length = 0;
    params[i].decimals      = 0;

    DEBUG_PRINTF("ODBC::GetParametersFromArray - &param[%i].length = %X\n",
                 i, &params[i].length);

    if (value->IsString()) {
      Local<String> string = value->ToString();
      int length = string->Length();
      
      params[i].c_type        = SQL_C_TCHAR;
#ifdef UNICODE
      params[i].type          = (length >= 8000) ? SQL_WLONGVARCHAR : SQL_WVARCHAR;
      params[i].buffer_length = (length * sizeof(uint16_t)) + sizeof(uint16_t);
#else
      params[i].type          = (length >= 8000) ? SQL_LONGVARCHAR : SQL_VARCHAR;
      params[i].buffer_length = string->Utf8Length() + 1;
#endif
      params[i].buffer        = malloc(params[i].buffer_length);
      params[i].size          = params[i].buffer_length;
      params[i].length        = SQL_NTS;//params[i].buffer_length;

#ifdef UNICODE
      string->Write((uint16_t *) params[i].buffer);
#else
      string->WriteUtf8((char *) params[i].buffer);
#endif

      DEBUG_PRINTF("ODBC::GetParametersFromArray - IsString(): params[%i] "
                   "c_type=%i type=%i buffer_length=%i size=%i length=%i "
                   "value=%s\n", i, params[i].c_type, params[i].type,
                   params[i].buffer_length, params[i].size, params[i].length, 
                   (char*) params[i].buffer);
    }
    else if (value->IsNull()) {
      params[i].c_type = SQL_C_DEFAULT;
      params[i].type   = SQL_VARCHAR;
      params[i].length = SQL_NULL_DATA;

      DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNull(): params[%i] "
                   "c_type=%i type=%i buffer_length=%i size=%i length=%i\n",
                   i, params[i].c_type, params[i].type,
                   params[i].buffer_length, params[i].size, params[i].length);
    }
    else if (value->IsInt32()) {
      int64_t  *number = new int64_t(value->IntegerValue());
      params[i].c_type = SQL_C_SBIGINT;
      params[i].type   = SQL_BIGINT;
      params[i].buffer = number;
      params[i].length = 0;
      
      DEBUG_PRINTF("ODBC::GetParametersFromArray - IsInt32(): params[%i] "
                   "c_type=%i type=%i buffer_length=%i size=%i length=%i "
                   "value=%lld\n", i, params[i].c_type, params[i].type,
                   params[i].buffer_length, params[i].size, params[i].length,
                   *number);
    }
    else if (value->IsNumber()) {
      double *number   = new double(value->NumberValue());
      
      params[i].c_type        = SQL_C_DOUBLE;
      params[i].type          = SQL_DECIMAL;
      params[i].buffer        = number;
      params[i].buffer_length = sizeof(double);
      params[i].length        = params[i].buffer_length;
      params[i].decimals      = 7;
      params[i].size          = sizeof(double);

      DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNumber(): params[%i] "
                  "c_type=%i type=%i buffer_length=%i size=%i length=%i "
		  "value=%f\n",
                  i, params[i].c_type, params[i].type,
                  params[i].buffer_length, params[i].size, params[i].length,
		  *number);
    }
    else if (value->IsBoolean()) {
      bool *boolean    = new bool(value->BooleanValue());
      params[i].c_type = SQL_C_BIT;
      params[i].type   = SQL_BIT;
      params[i].buffer = boolean;
      params[i].length = 0;
      
      DEBUG_PRINTF("ODBC::GetParametersFromArray - IsBoolean(): params[%i] "
                   "c_type=%i type=%i buffer_length=%i size=%i length=%i\n",
                   i, params[i].c_type, params[i].type,
                   params[i].buffer_length, params[i].size, params[i].length);
    }
  } 
  
  return params;
}
예제 #5
0
Parameter* ODBC::GetParametersFromArray (Local<Array> values, int *paramCount) {
    DEBUG_PRINTF("ODBC::GetParametersFromArray\n");
    *paramCount = values->Length();

    Parameter* params = NULL;

    if (*paramCount > 0) {
        params = (Parameter *) malloc(*paramCount * sizeof(Parameter));
    }

    for (int i = 0; i < *paramCount; i++) {
        Local<Value> value = values->Get(i);

        params[i].ColumnSize       = 0;
        params[i].StrLen_or_IndPtr = SQL_NULL_DATA;
        params[i].BufferLength     = 0;
        params[i].DecimalDigits    = 0;

        DEBUG_PRINTF("ODBC::GetParametersFromArray - param[%i].length = %lli\n",
                     i, params[i].StrLen_or_IndPtr);

        if (value->IsString()) {
            Local<String> string = value->ToString();
            int length = string->Length();

            params[i].ValueType         = SQL_C_TCHAR;
            params[i].ColumnSize        = 0; //SQL_SS_LENGTH_UNLIMITED
#ifdef UNICODE
            params[i].ParameterType     = SQL_WVARCHAR;
            params[i].BufferLength      = (length * sizeof(uint16_t)) + sizeof(uint16_t);
#else
            params[i].ParameterType     = SQL_VARCHAR;
            params[i].BufferLength      = string->Utf8Length() + 1;
#endif
            params[i].ParameterValuePtr = malloc(params[i].BufferLength);
            params[i].StrLen_or_IndPtr  = SQL_NTS;//params[i].BufferLength;

#ifdef UNICODE
            string->Write((uint16_t *) params[i].ParameterValuePtr);
#else
            string->WriteUtf8((char *) params[i].ParameterValuePtr);
#endif

            DEBUG_PRINTF("ODBC::GetParametersFromArray - IsString(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%s\n",
                         i, params[i].ValueType, params[i].ParameterType,
                         params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
                         (char*) params[i].ParameterValuePtr);
        }
        else if (value->IsNull()) {
            params[i].ValueType = SQL_C_DEFAULT;
            params[i].ParameterType   = SQL_VARCHAR;
            params[i].StrLen_or_IndPtr = SQL_NULL_DATA;

            DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNull(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli\n",
                         i, params[i].ValueType, params[i].ParameterType,
                         params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr);
        }
        else if (value->IsInt32()) {
            int64_t  *number = new int64_t(value->IntegerValue());
            params[i].ValueType = SQL_C_SBIGINT;
            params[i].ParameterType   = SQL_BIGINT;
            params[i].ParameterValuePtr = number;
            params[i].StrLen_or_IndPtr = 0;

            DEBUG_PRINTF("ODBC::GetParametersFromArray - IsInt32(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%lld\n",
                         i, params[i].ValueType, params[i].ParameterType,
                         params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
                         *number);
        }
        else if (value->IsNumber()) {
            double *number   = new double(value->NumberValue());

            params[i].ValueType         = SQL_C_DOUBLE;
            params[i].ParameterType     = SQL_DECIMAL;
            params[i].ParameterValuePtr = number;
            params[i].BufferLength      = sizeof(double);
            params[i].StrLen_or_IndPtr  = params[i].BufferLength;
            params[i].DecimalDigits     = 7;
            params[i].ColumnSize        = sizeof(double);

            DEBUG_PRINTF("ODBC::GetParametersFromArray - IsNumber(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli value=%f\n",
                         i, params[i].ValueType, params[i].ParameterType,
                         params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr,
                         *number);
        }
        else if (value->IsBoolean()) {
            bool *boolean = new bool(value->BooleanValue());
            params[i].ValueType         = SQL_C_BIT;
            params[i].ParameterType     = SQL_BIT;
            params[i].ParameterValuePtr = boolean;
            params[i].StrLen_or_IndPtr  = 0;

            DEBUG_PRINTF("ODBC::GetParametersFromArray - IsBoolean(): params[%i] c_type=%i type=%i buffer_length=%lli size=%lli length=%lli\n",
                         i, params[i].ValueType, params[i].ParameterType,
                         params[i].BufferLength, params[i].ColumnSize, params[i].StrLen_or_IndPtr);
        }
    }

    return params;
}