コード例 #1
0
ファイル: rs.cpp プロジェクト: mshogin/node-occi
Handle<Value> rs::Get_Clob(const Arguments& args) {
    HandleScope scope;
    rs* _this = node::ObjectWrap::Unwrap<rs>(args.This());

    int32_t num = args[0]->Int32Value();
    int32_t len = args[1]->Int32Value();

    Clob lClob = _this->_rs->getClob(num);

    if (lClob.isNull() ){
        return scope.Close(String::New(""));
    }

	lClob.open(OCCI_LOB_READONLY);

    const unsigned int BUFSIZE = len;
    unsigned char buffer[BUFSIZE];
    unsigned int readAmt=BUFSIZE;
    unsigned int offset=1;

    lClob.read(readAmt,buffer,BUFSIZE,offset);

    lClob.close();

	return scope.Close(String::New((const char*)buffer));
}
コード例 #2
0
ファイル: ocilib_demo.cpp プロジェクト: helloangel8002/ocilib
void test_object_fetch(void)
{
    ocout << otext("\n>>>>> TEST OBJECT FETCHING \n\n");

    Statement st(con);
    st.Execute(otext("select val from test_object for update"));

    Resultset rs = st.GetResultset();
    while (rs++)
    {
        Object obj = rs.Get<Object>(1);

        ocout << otext(".... val_int      : ") << obj.Get<int>(otext("VAL_INT")) << oendl;
        ocout << otext(".... val_dbl      : ") << obj.Get<double>(otext("VAL_DBL")) << oendl;
        ocout << otext(".... val_flt      : ") << obj.Get<float>(otext("VAL_FLT")) << oendl;
        ocout << otext(".... val_str      : ") << obj.Get<ostring>(otext("VAL_STR")) << oendl;
        ocout << otext(".... val_date     : ") << obj.Get<Date>(otext("VAL_DATE")) << oendl;

        Clob clob = obj.Get<Clob>(otext("VAL_LOB"));
        ocout << otext(".... val_lob      : ") << clob.Read(SizeBuffer) << oendl;

        File file = obj.Get<File>(otext("VAL_FILE"));
        ocout << otext(".... val_file     : ") << file.GetDirectory() << otext("/") << file.GetName() << oendl;

        Raw raw = obj.Get<Raw>(otext("VAL_RAW"));
        raw.push_back(0);
        ocout << otext(".... val_raw      : ") << reinterpret_cast<char *>(raw.data()) << oendl;

        Object obj2 = obj.Get<Object>(otext("VAL_OBJ"));
        ocout << otext(".... val_obj.code : ") << obj2.Get<int>(otext("ID")) << oendl;
        ocout << otext(".... val_obj.name : ") << obj2.Get<ostring>(otext("NAME")) << oendl;
    }

    con.Commit();

    ocout << otext("\n>>>>> TEST OBJECT FETCHING  AS STRING \n\n");

    st.Execute(otext("select val from test_object"));

    rs = st.GetResultset();
    while (rs++)
    {
        ocout << rs.Get<Object>(1) << oendl;
    }
}
コード例 #3
0
ファイル: ocilib_demo.cpp プロジェクト: helloangel8002/ocilib
void test_lob(void)
{
    ocout << otext("\n>>>>> TEST LOB MANIPULATION\n\n");

    Statement st(con);
    st.Execute(otext("select code, content from test_lob where code=1 for update"));

    Resultset rs = st.GetResultset();
    while (rs++)
    {
        Clob clob = rs.Get<Clob>(2);

        clob.Write(otext("today, "));
        clob.Append(otext("i'm going to the cinema ! "));
        clob.Seek(SeekSet, 0);

        ocout << otext("> code : ") << rs.Get<int>(1) << otext(", content : ") << clob.Read(SizeString) << oendl;
    }

    con.Commit();

    ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl;
}
コード例 #4
0
ファイル: ocilib_demo.cpp プロジェクト: helloangel8002/ocilib
void test_returning(void)
{
    ocout << otext("\n>>>>> TEST RETURNING CLAUSE \n\n");

    Statement st(con);
    st.Prepare(otext("update test_lob set code = code + 1 returning code, content into :i, :l"));
    st.Register<int>(otext(":i"));
    st.Register<Clob>(otext(":l"));
    st.ExecutePrepared();

    Resultset rs = st.GetResultset();
    while (rs++)
    {
        Clob clob = rs.Get<Clob>(2);
        clob.Append(otext("(modified)"));
        clob.Seek(SeekSet, 0);

        ocout << otext("> code : ") << rs.Get<int>(1) << otext(" - ") << clob.Read(static_cast<unsigned int>(clob.GetLength())) << oendl;
    }

    con.Commit();

    ocout << oendl << rs.GetCount() << otext(" row(s) fetched") << oendl;
}
コード例 #5
0
ファイル: rs.cpp プロジェクト: mshogin/node-occi
Handle<Value> rs::Fetch(const v8::Arguments& args){
    HandleScope scope;
    rs* _this = node::ObjectWrap::Unwrap<rs>(args.This());

    std::vector<MetaData> metaData = _this->_rs->getColumnListMetaData();

    int columnCount = metaData.size();

    if ( columnCount > 0 ){

    	int32_t arrayIndex = 0;

    	if ( _this->_rs->next() ){
    		Local<Object> js_field_obj = Object::New();

	    	Local<String> pName;

	    	for ( int i = 0; i < columnCount; i++ ) {
	    		pName = V8STR(metaData[i].getString(MetaData::ATTR_NAME).c_str());

	    		int pNum = i+1;
    	    	switch ( metaData[i].getInt(MetaData::ATTR_DATA_TYPE) ){
    	    		case OCCI_SQLT_AFC :
    	    		case OCCI_SQLT_VCS :
    	    		case OCCI_SQLT_STR :
    	    		case OCCI_SQLT_CHR : {
    	    				std::string pVal = _this->_rs->getString(pNum);
    	    	    	    js_field_obj->Set(
    	    					pName,
    	    					V8STR(pVal.c_str())
    	    				);
    	    			}
    	    	        break;
    	    		case OCCIFLOAT :
    	    		case OCCI_SQLT_NUM : {
    	    				double pVal = _this->_rs->getDouble(pNum);
    	    	    	    js_field_obj->Set(
    	    					pName,
    	    					v8::Number::New(pVal)
    	    				);
    	    			}
    	    	        break;
    	    		case OCCIINT : {
    	    				int32_t pVal = _this->_rs->getInt(pNum);
    	    				js_field_obj->Set(
    	    					pName,
    	    					v8::Integer::NewFromUnsigned(pVal)
    	    	    		);
    	    			}
    	    			break;
    	    		case OCCI_SQLT_CLOB: {
							Clob lClob = _this->_rs->getClob(pNum);
							lClob.setCharSetForm(OCCI_SQLCS_NCHAR);
							if (lClob.isNull() ){
								js_field_obj->Set(
	    	    					pName,
	    	    					String::New("")
	    	    	    		);
							}
							else {
								lClob.open(OCCI_LOB_READONLY);

								const unsigned int BUFSIZE = 100000;
								unsigned char buffer[BUFSIZE];
								unsigned int readAmt=BUFSIZE;
								unsigned int offset=1;

								memset(buffer,0,sizeof(buffer));
								lClob.read(readAmt,buffer,BUFSIZE,offset);

								lClob.close();

								js_field_obj->Set(
	    	    					pName,
	    	    					String::New((const char*)buffer)
	    	    	    		);
							}
    	    			}
    	    	        break;
    	    	}
    	    }

	    	return scope.Close(js_field_obj);
    	}
    }

    return scope.Close(False());
}
コード例 #6
0
ファイル: ocilib_demo.cpp プロジェクト: helloangel8002/ocilib
void test_returning_array(void)
{
    ocout << otext("\n>>>>> TEST ARRAY BINDING WITH RETURNING CLAUSE \n\n");

    std::vector<int>     tab_int;
    std::vector<double>  tab_dbl;
    std::vector<float>   tab_flt;
    std::vector<ostring> tab_str;
    std::vector<Date>    tab_date;
    std::vector<Clob>    tab_lob;
    std::vector<File>    tab_file;


    for (int i = 0; i < ElemCount; i++)
    {
        tab_int.push_back(i + 1);
        tab_dbl.push_back(3.14*static_cast<double>(i + 1));
        tab_flt.push_back(3.14f*static_cast<float>(i + 1));

        ostring str;
        str += otext("Name");
        str += ((i + 1) + '0');
        tab_str.push_back(str);

        tab_date.push_back(Date::SysDate());

        Clob clob(con);
        clob.Write(otext("Lob value ") + str);
        tab_lob.push_back(clob);

        ostring fileName;
        fileName += otext("File");
        fileName += ((i + 1) + '0');
        File file(con, otext("Mydir"), fileName);
        tab_file.push_back(file);
    }

    Statement st(con);

    st.Prepare(otext("insert into test_array ")
        otext("( ")
        otext("   val_int,  val_dbl, val_flt, val_str, val_date, ")
        otext("   val_lob, val_file ")
        otext(") ")
        otext("values ")
        otext("( ")
        otext("   :val_int, :val_dbl, :val_flt, :val_str, :val_date, ")
        otext("   :val_lob, :val_file ")
        otext(") ")
        otext("returning")
        otext("  val_int,  val_dbl, val_flt, val_str, val_date, ")
        otext("   val_lob, val_file ")
        otext("into  ")
        otext("  :out_int, :out_dbl, :out_flt,  :out_str, :out_date, ")
        otext("   :out_lob, :out_file "));

    st.SetBindArraySize(ElemCount);

    /* bind vectors */
    st.Bind(otext(":val_int"), tab_int, BindInfo::In);
    st.Bind(otext(":val_dbl"), tab_dbl, BindInfo::In);
    st.Bind(otext(":val_flt"), tab_flt, BindInfo::In);
    st.Bind(otext(":val_date"), tab_date, BindInfo::In);
    st.Bind(otext(":val_lob"), tab_lob, BindInfo::In);
    st.Bind(otext(":val_file"), tab_file, BindInfo::In);
    st.Bind(otext(":val_str"), tab_str, 30, BindInfo::In);

    /* register output */
    st.Register<int    >(otext(":out_int"));
    st.Register<double >(otext(":out_dbl"));
    st.Register<float  >(otext(":out_flt"));
    st.Register<Date   >(otext(":out_date"));
    st.Register<Clob   >(otext(":out_lob"));
    st.Register<File   >(otext(":out_file"));
    st.Register<ostring>(otext(":out_str"), 30);

    st.ExecutePrepared();
    ocout << oendl << st.GetAffectedRows() << otext(" row(s) inserted") << oendl;

    int rowIndex = 0;

    Resultset rs = st.GetResultset();
    while (!rs.IsNull())
    {
        while (rs++)
        {
            ocout << otext("Row #") << ++rowIndex << otext("---------------") << oendl;

            ocout << otext(".... val_int    : ") << rs.Get<int>(otext(":OUT_INT")) << oendl;
            ocout << otext(".... val_dbl    : ") << rs.Get<double>(otext(":OUT_DBL")) << oendl;
            ocout << otext(".... val_flt    : ") << rs.Get<float>(otext(":OUT_FLT")) << oendl;
            ocout << otext(".... val_str    : ") << rs.Get<ostring>(otext(":OUT_STR")) << oendl;
            ocout << otext(".... val_date   : ") << rs.Get<Date>(otext(":OUT_DATE")) << oendl;

            Clob clob = rs.Get<Clob>(otext(":OUT_LOB"));
            ocout << otext(".... val_lob    : ") << clob.Read(SizeBuffer) << oendl;

            File file = rs.Get<File>(otext(":OUT_FILE"));
            ocout << otext(".... val_file   : ") << file.GetDirectory() << otext("/") << file.GetName() << oendl;
        }

        rs = st.GetNextResultset();
    }
}
コード例 #7
0
int main()
{
  cout << "***OCCI Globalization Support demo program.***" << endl;
  cout << "***This program loads Unicode data files into a NClob attribute***" << endl;

  char *unicodefiles[4] = {"occiuni2_hindi.txt", "occiuni2_russian.txt", "occiuni2_korean.txt",
                            "occiuni2_japanese.txt"};
  try
  {

     cout << "Initializing OCCI environment in Unicode mode" << endl;
     //initialize in Unicode(UTF16) mode
     Environment *utf16env = Environment::createEnvironment( "OCCIUTF16",
                        "OCCIUTF16", Environment::OBJECT );
     occiuni2m(utf16env);

     //"L" prefix will create a widechar i.e Unicode literal which is equivalent to
     // OCCI's UString datatype
     Connection *conn = utf16env->createConnection( L"hr",L"hr",L"" );

     //load the 4 sample Unicode files
     for (int i = 0; i < 4;i++)
     {
      //convert the filename argument to Unicode. We will be saving the filename
      //as one of the attributes of the object.
      const char *asciifilename = unicodefiles[i];
      wchar_t wcfilename[100];
      MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, (LPCSTR)asciifilename, 
                           strlen(asciifilename)+1, (LPWSTR)wcfilename, 100 );
      wstring docname(wcfilename);

      cout << "Loading " << asciifilename << endl;


      //Create a persistent object, set the NClob to empty and save
      //the object. Use the overloaded new operator that takes UString
      //arugments
      DocObjType *newdoc = new (conn, L"DOCUMENTSTAB",L"DOCOBJTYPE",
                                L"HR",L"HR") DocObjType();

      newdoc->setDocname(docname);

      //first insert a empty clob
      Clob doccontents(conn);
      doccontents.setEmpty();
      newdoc->setDoctext(doccontents);//empty 

      conn->commit();

      //Now, we will select the object again and add the document text
      //to the NClob attribute. 
      Statement *stmt = conn->createStatement(
      L"select ref(a) from documentstab a where docname = :1 for update");

      stmt->setUString(1, docname);//bind wstring
      ResultSet *rs = stmt->executeQuery();

      rs->next();//this will actually fetch the Ref

      Ref<DocObjType> docobjref = rs->getRef(1);
      DocObjType *docobj = docobjref.ptr();//pin the object

      doccontents = docobj->getDoctext();//get the Clob
      doccontents.open();

      doccontents.setCharSetId("OCCIUTF16");
      doccontents.setCharSetForm(OCCI_SQLCS_NCHAR);

      ifstream in( asciifilename, ios::binary );
      int bytesread=0, totalbytesread=0, wcharsread=0;
      wchar_t wbuffer1[50];//50 chars = 100 bytes at a time

      //we have stored the data in a Unicode text file. The first
      //character (2 bytes) is a Unicode Byte-Order-Mark and 
      //indicates whether the data in the file is little-endian or
      //big-endian
      in.read((char *)wbuffer1,2);//read & skip BOM
      int offset = 1;

      while (in.read( (char *)wbuffer1,sizeof(wbuffer1) ))
      {
        bytesread = in.gcount();
        wcharsread = bytesread/2;

        //write to the NClob
        doccontents.writeChunk( wcharsread, (utext *)wbuffer1, sizeof(wbuffer1), offset );

        offset += wcharsread;//offset is in terms of characters
        totalbytesread += bytesread;
      }
      //last chunk
      bytesread = in.gcount();
      wcharsread = bytesread/2;      
      totalbytesread += bytesread;

      doccontents.writeChunk( wcharsread, (utext *)wbuffer1, bytesread, offset );
      doccontents.close();

      //update the object and flush to database
      docobj->setDoctext(doccontents);
      docobj->markModified();
      docobj->flush();
      conn->commit();


      cout << totalbytesread/2 << " characters saved" << endl;

      //Statement & ResultSet objects will be created again
      stmt->closeResultSet(rs);
      conn->terminateStatement(stmt);
     }//for (i = 0; i < 4)


     cout << "Now reading the NClob data back and saving to new files" << endl;

     Statement *selectstmt = conn->createStatement(
     L"select ref(a) from DocumentsTab a" );
     ResultSet *queryrs = selectstmt->executeQuery();
     wstring wfilehdrtxt = L"If you cannot see the text properly, try setting your font to a Unicode font like : - Arial Unicode MS, Lucinda Sans Unicode etc...";
     while (queryrs->next())
     {
        Ref<DocObjType> docobjref = queryrs->getRef(1);

        wstring docname = docobjref->getDocname();

        //create the output file, prepend "fetch_" to the original filename
        docname = L"fetch_" + docname;
        char asciifilenamebuf[100];

        int ret = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)docname.c_str(),
                  docname.length()+1, (LPSTR)asciifilenamebuf, 100, NULL, NULL);

        cout << "Creating Unicode textfile " << asciifilenamebuf << endl;
        ofstream outdoc(asciifilenamebuf, ios_base::binary | ios_base::trunc);

        //first write the BOM
        wchar_t bom = 0xFEFF;//Windows is little-endian
        outdoc.write((char *)&bom, 2);

        outdoc.write((char *)wfilehdrtxt.c_str(), wfilehdrtxt.length()*2);

        Clob doccontents = docobjref->getDoctext();
        doccontents.setCharSetId("OCCIUTF16");
        doccontents.setCharSetForm(OCCI_SQLCS_NCHAR);
        int offset = 1;
        int clobcharsread=0;
        //now read the NClob and write to file
        wchar_t wbuffer2[100];//100 chars at a time
        while ( (clobcharsread = 
                 doccontents.read(100, wbuffer2, sizeof(wbuffer2), offset)) !=0 )
        {
            offset = offset+clobcharsread;
            outdoc.write((char *)wbuffer2,clobcharsread*2);//write takes number of bytes
        }
        outdoc.close();

      }//while (queryrs->next())

      //done
      cout << "You can view the created files in Notepad(or any other editor that displays Unicode)" << endl;
      selectstmt->closeResultSet(queryrs);
      conn->terminateStatement(selectstmt);

      //delete the rows from the table
      //if you want to retain the rows, comment out 
      cout << "Cleaning up table" << endl;
      Statement *deletestmt = conn->createStatement(
      L"delete from DocumentsTab");
      deletestmt->executeUpdate();

      conn->commit();

      utf16env->terminateConnection(conn);
      Environment::terminateEnvironment(utf16env);

      cout << "Done" << endl;

  }
  catch (SQLException &e)
  {
         std::cout << e.getErrorCode() << std::endl;
  }
  return 0;
}
コード例 #8
0
ファイル: versions.cpp プロジェクト: MAPJe71/libyuni
	void List::loadFromPath(const String& folder)
	{
		String path;
		IO::Canonicalize(path, folder);
		if (pOptDebug)
			std::cout << "[yuni-config][debug] :: reading `" << path << "`" << std::endl;

		VersionInfo::Settings info;
		info.mapping = mappingStandard;

		String s;
		s << path << SEP << "yuni.version";
		if (not IO::File::Exists(s))
		{
			s.clear() << path << SEP << "include" << SEP << "yuni" << SEP << "yuni.version";
			if (not IO::File::Exists(s))
			{
				info.mapping = mappingSVNSources;
				s.clear() << path << SEP << "src" << SEP << "yuni" << SEP << "yuni.version";
				if (not IO::File::Exists(s))
                {
					if (pOptDebug)
						std::cout << "[yuni-config][debug] :: " << s << " not found" << std::endl;
					return;
                }
			}
		}

		IO::File::Stream file;
		if (file.open(s))
		{
			String key;
			String value;

			Version version;

			// A buffer. The given capacity will be the maximum length for a single line
			Clob buffer;
			buffer.reserve(8000);
			while (file.readline(buffer))
			{
				buffer.extractKeyValue(key, value);

				if (key.empty() || key == "[")
					continue;
				if (key == "version.hi")
					version.hi = value.to<unsigned int>();
				if (key == "version.lo")
					version.lo = value.to<unsigned int>();
				if (key == "version.rev")
					version.revision = value.to<unsigned int>();
				if (key == "version.target")
					info.compilationMode = value;
				if (key == "modules.available")
					value.split(info.modules, ";\"', \t", false);
				if (key == "support.opengl")
					info.supportOpenGL = value.to<bool>();
				if (key == "support.directx")
					info.supportDirectX = value.to<bool>();
				if (key == "redirect")
					loadFromPath(value);
				if (key == "path.include")
				{
					if (not value.empty())
						info.includePath.push_back(value);
				}
				if (key == "path.lib")
				{
					if (not value.empty())
						info.libPath.push_back(value);
				}
			}

			if (not version.null() and not info.modules.empty())
			{
				info.path = path;
				info.compiler = pCompiler;
				pList[version] = info;

				if (pOptDebug)
				{
					std::cout << "[yuni-config][debug]  - found installation `" << path
						<< "` (" << version << ")" << std::endl;
				}
			}
			else
			{
				std::cerr << "error: " << s << ": invalid file";
				if (version.null())
					std::cerr << " (invalid version)" << std::endl;
				else if (info.modules.empty())
					std::cerr << " (no module)" << std::endl;
			}
		}
	}