Esempio n. 1
0
void CGlobalRecords::char2str16(const string& str1, u16string& str2)
{
	string::const_iterator cBegin, cEnd;
	size_t len;

	str2.clear();

	// test for UTF
	cBegin	= str1.begin();
	cEnd	= str1.end();

	unsigned8_t c = 0;
	while(cBegin != cEnd) {
		c |= *cBegin++;
	}

	if(c & 0x80) {
		const char				*inbuf;
		iconv_t	cd;
		unsigned16_t			*outbuf, *origOutbuf;
		size_t resultSize, inbytesleft, outbytesleft;

		cd = iconv_open(UCS_2_INTERNAL, "UTF-8");
		XL_ASSERT(cd != (iconv_t)(-1));

		inbytesleft		= str1.size();
		outbytesleft	= inbytesleft * sizeof(unsigned16_t);

		inbuf		= str1.c_str();
		origOutbuf	= (unsigned16_t *)calloc(outbytesleft, 1);
		outbuf		= origOutbuf;

		resultSize = iconv(cd, (char **)&inbuf, &inbytesleft, (char **)&outbuf, &outbytesleft);
		iconv_close(cd);

		if(resultSize == (size_t)-1) {
			str2 = convFail;
		} else {
			str2.assign(origOutbuf, (size_t)(outbuf - origOutbuf));
		}
		free((void *)origOutbuf);
	} else {
		len = str1.length();
		str2.reserve(len);

		cBegin	= str1.begin();
		cEnd	= str1.end();

		while(cBegin != cEnd) {
			str2.push_back((unsigned16_t)*cBegin++);
		}
		XL_ASSERT(str2.length() == str1.length());
	}
}
Esempio n. 2
0
bool CGlobalRecords::IsASCII(const u16string& str)
{
	u16string::const_iterator cBegin, cEnd;

	cBegin	= str.begin();
	cEnd	= str.end();

	unsigned16_t c = 0;

	while(cBegin != cEnd) {
		c |= *cBegin++;
	}

	return c <= 0x7F;
}
Esempio n. 3
0
void CGlobalRecords::wide2str16(const ustring& str1, u16string& str2)
{
	size_t					resultSize, inbytesleft, outbytesleft;
	const uint8_t			*inbuf;
	iconv_t					cd;
	unsigned16_t			*outbuf, *origOutbuf = NULL;

	cd = iconv_open(UCS_2_INTERNAL, iconv_code.c_str());
	// user may have changed the conversion since the workbook was opened
	XL_ASSERT(!(cd == (iconv_t)(-1)));

	if(cd != (iconv_t)(-1)) {
		inbytesleft		= str1.size() * sizeof(unichar_t);
		outbytesleft	= str1.size() * sizeof(unsigned16_t);

		inbuf		= (uint8_t *)str1.data();
		origOutbuf	= (unsigned16_t *)calloc(outbytesleft, 1);
		outbuf		= origOutbuf;

		resultSize = iconv(cd, (char **)&inbuf, &inbytesleft, (char **)&outbuf, &outbytesleft);
		iconv_close(cd);
	} else {
		resultSize = (size_t)-1;
	}

	if(resultSize == (size_t)-1) {
		str2 = convFail;
	} else {
		str2.assign(origOutbuf, (size_t)(outbuf - origOutbuf));
	}
	free((void *)origOutbuf);
}
Esempio n. 4
0
void CGlobalRecords::char2str16(const std::string& str1, u16string& str2)
{
	std::string::const_iterator cBegin, cEnd;
	size_t len;

	str2.clear();

	len = str1.length();
	str2.reserve(len);

	cBegin	= str1.begin();
	cEnd	= str1.end();

	while(cBegin != cEnd) {
		str2.push_back((unsigned16_t)*cBegin++);
	}
	XL_ASSERT(str2.length() == str1.length());
}
Esempio n. 5
0
void CGlobalRecords::str16toascii(const u16string& str1, std::string& str2)
{
	u16string::const_iterator cBegin, cEnd;

	str2.clear();

	size_t len = str1.length();
	str2.reserve(len);


	cBegin	= str1.begin();
	cEnd	= str1.end();

	while(cBegin != cEnd) {
		unsigned16_t c = *cBegin++;

		if (c > 0x7F) {
			c = '?';
		}
		str2.push_back((char)c);
	}
}
Esempio n. 6
0
inline command::command(const std::string& srv_, const std::string& usr_, const std::string& pwd_) : m_autocommit(true)
{
  using namespace std;
  using namespace brig::unicode;

  const u16string
    srv(transform<char16_t>(srv_)),
    usr(transform<char16_t>(usr_)),
    pwd(transform<char16_t>(pwd_)),
    type_schema(transform<char16_t>("MDSYS")),
    type_name(transform<char16_t>("SDO_GEOMETRY"));

  try
  {
    if (lib::singleton().empty()) throw runtime_error("OCI error");
    OCIEnv* env(0);
    m_hnd.check(lib::singleton().p_OCIEnvNlsCreate(&env, OCI_THREADED|OCI_NO_MUTEX|OCI_OBJECT, 0, 0, 0, 0, 0, 0, OCI_UTF16ID, OCI_UTF16ID));
    m_hnd.env = env;
    m_hnd.alloc_handle((void**)&m_hnd.err, OCI_HTYPE_ERROR);
    m_hnd.alloc_handle((void**)&m_hnd.srv, OCI_HTYPE_SERVER);
    m_hnd.alloc_handle((void**)&m_hnd.svc, OCI_HTYPE_SVCCTX);
    m_hnd.alloc_handle((void**)&m_hnd.ses, OCI_HTYPE_SESSION);
    m_hnd.check(lib::singleton().p_OCIServerAttach(m_hnd.srv, m_hnd.err, (const text*)srv.c_str(), ub4(srv.size() * sizeof(char16_t)), OCI_DEFAULT));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.svc, OCI_HTYPE_SVCCTX, (void*)m_hnd.srv, 0, OCI_ATTR_SERVER, m_hnd.err));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.ses, OCI_HTYPE_SESSION, (void*)usr.c_str(), ub4(usr.size() * sizeof(char16_t)), OCI_ATTR_USERNAME, m_hnd.err));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.ses, OCI_HTYPE_SESSION, (void*)pwd.c_str(), ub4(pwd.size() * sizeof(char16_t)), OCI_ATTR_PASSWORD, m_hnd.err));
    m_hnd.check(lib::singleton().p_OCISessionBegin(m_hnd.svc, m_hnd.err, m_hnd.ses, OCI_CRED_RDBMS, OCI_DEFAULT));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.svc, OCI_HTYPE_SVCCTX, (void*)m_hnd.ses, 0, OCI_ATTR_SESSION, m_hnd.err));
    OCIType* type(0);
    m_hnd.check(lib::singleton().p_OCITypeByName
      ( m_hnd.env, m_hnd.err, m_hnd.svc
      , (const text*)type_schema.c_str(), ub4(type_schema.size() * sizeof(char16_t))
      , (const text*)type_name.c_str(), ub4(type_name.size() * sizeof(char16_t))
      , (const text*)0, 0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, &type));
    m_hnd.geom = type;
  }
  catch (const exception&)  { close_all(); throw; }
}
Esempio n. 7
0
HRESULT CGUIContainer::Render(GUIState* pGUIState, float fElapsedTime)
{
	SetDirty(false);

	m_objResource->SetActiveLayer();
	m_objResource->SetCurrentState();

	if (m_position.IsRelativeTo3DObject())
	{
		BeginDepthTest(pGUIState);
		UpdateRects();
	}

	RECT rcScreen;//rcScreen is the rect of this container
	//render background first
	rcScreen = m_objResource->GetDrawingRects(2);

	if (m_objResource->GetLayerType() == GUILAYER::ONE_ELEMENT)
	{
		DrawElement(m_objResource->GetTextureElement(0), &rcScreen, &rcScreen);
	}
	else if (m_objResource->GetLayerType() == GUILAYER::NINE_ELEMENT)
	{
		for (int e = 0; e < 9; ++e)
		{
			auto rc = m_objResource->GetDrawingRects(e + 3);
			DrawElement(m_objResource->GetTextureElement(e), &rc, &rcScreen, pGUIState);
		}
	}

	GUIBase_List_Type::iterator iter, iterend;
	iterend = this->GetChildren()->end();
	bool bRender = false;
	if (m_bBatching)
	{
		RECT rctext;
		SetRect(&rctext, 5, 5, 60, 30);
		static u16string sText;
		if (sText.empty())
			StringHelper::UTF8ToUTF16_Safe("Updating", sText);
		GetPainter(pGUIState)->DrawText(sText.c_str(), m_objResource->GetFontElement(0), &rctext, m_position.GetDepth());
	}
	else
	{
		for (iter = this->GetChildren()->begin(); iter != iterend; iter++)
		{
			CGUIBase* pObjChild = *iter;
			/// skip any node that is not visible
			if (!(pObjChild->m_bIsVisible))
				continue;
			RECT rcChild;
			bRender = false;

			if (!pObjChild->GetPosition()->IsRelativeTo3DObject())
			{
				if (pObjChild->m_bNeedUpdate)
					pObjChild->UpdateRects();
				rcChild = pObjChild->m_objResource->GetDrawingRects(0);
				if (GetFastRender() || RectIntersect(rcChild, rcScreen)){
					bRender = true;
				}
				else
					bRender = false;
			}
			if (bRender)
			{
				pObjChild->DoRender(pGUIState, fElapsedTime);
			}
		}
	}

	if (m_position.IsRelativeTo3DObject())
	{
		EndDepthTest(pGUIState);
	}
	OnFrameMove(fElapsedTime);

	return S_OK;
}
Esempio n. 8
0
namespace brig { namespace database { namespace oracle { namespace detail {

class command : public brig::database::command {
  handles m_hnd;
  ::boost::ptr_vector<define> m_cols;
  bool m_autocommit;

  void close_stmt();
  void close_all();

public:
  command(const std::string& srv, const std::string& usr, const std::string& pwd);
  ~command() override  { close_all(); }
  void exec(const std::string& sql, const std::vector<column_def>& params = std::vector<column_def>()) override;
  void exec_batch(const std::string& sql) override;
  std::vector<std::string> columns() override;
  bool fetch(std::vector<variant>& row) override;
  void set_autocommit(bool autocommit) override;
  void commit() override;
  DBMS system() override  { return DBMS::Oracle; }
  std::string sql_param(size_t order) override  { return ":" + string_cast<char>(order + 1); }
  bool readable_geom() override { return true; }
  bool writable_geom() override { return true; }
}; // command

inline void command::close_stmt()
{
  m_cols.clear();
  handles::free_handle((void**)&m_hnd.stmt, OCI_HTYPE_STMT);
}

inline void command::close_all()
{
  m_autocommit = true;
  close_stmt();
  m_hnd.geom = 0;
  handles::free_handle((void**)&m_hnd.ses, OCI_HTYPE_SESSION);
  handles::free_handle((void**)&m_hnd.svc, OCI_HTYPE_SVCCTX);
  handles::free_handle((void**)&m_hnd.srv, OCI_HTYPE_SERVER);
  handles::free_handle((void**)&m_hnd.err, OCI_HTYPE_ERROR);
  handles::free_handle((void**)&m_hnd.env, OCI_HTYPE_ENV);
}

inline command::command(const std::string& srv_, const std::string& usr_, const std::string& pwd_) : m_autocommit(true)
{
  using namespace std;
  using namespace brig::unicode;

  const u16string
    srv(transform<char16_t>(srv_)),
    usr(transform<char16_t>(usr_)),
    pwd(transform<char16_t>(pwd_)),
    type_schema(transform<char16_t>("MDSYS")),
    type_name(transform<char16_t>("SDO_GEOMETRY"));

  try
  {
    if (lib::singleton().empty()) throw runtime_error("OCI error");
    OCIEnv* env(0);
    m_hnd.check(lib::singleton().p_OCIEnvNlsCreate(&env, OCI_THREADED|OCI_NO_MUTEX|OCI_OBJECT, 0, 0, 0, 0, 0, 0, OCI_UTF16ID, OCI_UTF16ID));
    m_hnd.env = env;
    m_hnd.alloc_handle((void**)&m_hnd.err, OCI_HTYPE_ERROR);
    m_hnd.alloc_handle((void**)&m_hnd.srv, OCI_HTYPE_SERVER);
    m_hnd.alloc_handle((void**)&m_hnd.svc, OCI_HTYPE_SVCCTX);
    m_hnd.alloc_handle((void**)&m_hnd.ses, OCI_HTYPE_SESSION);
    m_hnd.check(lib::singleton().p_OCIServerAttach(m_hnd.srv, m_hnd.err, (const text*)srv.c_str(), ub4(srv.size() * sizeof(char16_t)), OCI_DEFAULT));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.svc, OCI_HTYPE_SVCCTX, (void*)m_hnd.srv, 0, OCI_ATTR_SERVER, m_hnd.err));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.ses, OCI_HTYPE_SESSION, (void*)usr.c_str(), ub4(usr.size() * sizeof(char16_t)), OCI_ATTR_USERNAME, m_hnd.err));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.ses, OCI_HTYPE_SESSION, (void*)pwd.c_str(), ub4(pwd.size() * sizeof(char16_t)), OCI_ATTR_PASSWORD, m_hnd.err));
    m_hnd.check(lib::singleton().p_OCISessionBegin(m_hnd.svc, m_hnd.err, m_hnd.ses, OCI_CRED_RDBMS, OCI_DEFAULT));
    m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.svc, OCI_HTYPE_SVCCTX, (void*)m_hnd.ses, 0, OCI_ATTR_SESSION, m_hnd.err));
    OCIType* type(0);
    m_hnd.check(lib::singleton().p_OCITypeByName
      ( m_hnd.env, m_hnd.err, m_hnd.svc
      , (const text*)type_schema.c_str(), ub4(type_schema.size() * sizeof(char16_t))
      , (const text*)type_name.c_str(), ub4(type_name.size() * sizeof(char16_t))
      , (const text*)0, 0, OCI_DURATION_SESSION, OCI_TYPEGET_HEADER, &type));
    m_hnd.geom = type;
  }
  catch (const exception&)  { close_all(); throw; }
}

inline void command::exec(const std::string& sql_, const std::vector<column_def>& params)
{
  using namespace std;

  close_stmt();
  m_hnd.alloc_handle((void**)&m_hnd.stmt, OCI_HTYPE_STMT);
  const u16string sql(brig::unicode::transform<char16_t>(sql_));
  m_hnd.check(lib::singleton().p_OCIStmtPrepare(m_hnd.stmt, m_hnd.err, (const text*)sql.c_str(), ub4(sql.size() * sizeof(char16_t)), OCI_NTV_SYNTAX, OCI_DEFAULT));
  ub2 stmt_type(0);
  m_hnd.check(lib::singleton().p_OCIAttrGet(m_hnd.stmt, OCI_HTYPE_STMT, &stmt_type, 0, OCI_ATTR_STMT_TYPE, m_hnd.err));

  ::boost::ptr_vector<binding> binds;
  for (size_t i(0); i < params.size(); ++i)
    binds.push_back(binding_factory(&m_hnd, i, params[i]));

  m_hnd.check(lib::singleton().p_OCIStmtExecute(m_hnd.svc, m_hnd.stmt, m_hnd.err, OCI_STMT_SELECT == stmt_type? 0: 1, 0, 0, 0, m_autocommit? OCI_COMMIT_ON_SUCCESS: OCI_DEFAULT));
}

inline void command::exec_batch(const std::string& sql)
{
  exec(sql);
  close_stmt();
}

inline std::vector<std::string> command::columns()
{
  using namespace std;
  using namespace brig::unicode;

  vector<string> cols;
  if (0 == m_hnd.stmt) return cols;
  m_cols.clear();
  ub4 count(0);
  m_hnd.check(lib::singleton().p_OCIAttrGet(m_hnd.stmt, OCI_HTYPE_STMT, &count, 0, OCI_ATTR_PARAM_COUNT, m_hnd.err));
  for (ub4 i(0); i < count; ++i)
  {
    OCIParam *dsc(0);
    m_hnd.check(lib::singleton().p_OCIParamGet(m_hnd.stmt, OCI_HTYPE_STMT, m_hnd.err, (void**)&dsc, i + 1));
    try
    {

      ub2 data_type(0), size(0);
      sb2 precision(0);
      sb1 scale(-1);
      ub1 charset_form(SQLCS_NCHAR);
      utext *name(0), *nty_schema(0), *nty(0);
      ub4 name_len(0), nty_schema_len(0), nty_len(0);

      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &name, &name_len, OCI_ATTR_NAME, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &data_type, 0, OCI_ATTR_DATA_TYPE, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &size, 0, OCI_ATTR_DATA_SIZE, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &precision, 0, OCI_ATTR_PRECISION, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &scale, 0, OCI_ATTR_SCALE, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &charset_form, 0, OCI_ATTR_CHARSET_FORM, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &nty_schema, &nty_schema_len, OCI_ATTR_SCHEMA_NAME, m_hnd.err));
      m_hnd.check(lib::singleton().p_OCIAttrGet(dsc, OCI_DTYPE_PARAM, &nty, &nty_len, OCI_ATTR_TYPE_NAME, m_hnd.err));

      identifier nty_lcase = { transform<char>(nty_schema, lower_case), transform<char>(nty, lower_case), "" };

      m_cols.push_back(define_factory(&m_hnd, i + 1, data_type, size, precision, scale, charset_form, nty_lcase));
      cols.push_back(transform<char>(name));

    }
    catch (const exception&)  { handles::free_descriptor((void**)&dsc, OCI_DTYPE_PARAM); throw; }
    handles::free_descriptor((void**)&dsc, OCI_DTYPE_PARAM);
  }

  ub4 rows = ub4(PageSize);
  m_hnd.check(lib::singleton().p_OCIAttrSet(m_hnd.stmt, OCI_HTYPE_STMT, &rows, 0, OCI_ATTR_PREFETCH_ROWS, m_hnd.err));
  return cols;
}

inline bool command::fetch(std::vector<variant>& row)
{
  if (0 == m_hnd.stmt) return false;
  if (m_cols.empty()) columns();

  const sword r(lib::singleton().p_OCIStmtFetch2(m_hnd.stmt, m_hnd.err, 1, OCI_FETCH_NEXT, 1, OCI_DEFAULT));
  if (OCI_NO_DATA == r) return false;
  m_hnd.check(r);

  row.resize(m_cols.size());
  for (size_t i(0); i < m_cols.size(); ++i)
    m_cols[i](row[i]);
  return true;
}

inline void command::set_autocommit(bool autocommit)
{
  close_stmt();
  if (m_autocommit == autocommit) return;
  if (autocommit) m_hnd.check(lib::singleton().p_OCITransRollback(m_hnd.svc, m_hnd.err, OCI_DEFAULT));
  m_autocommit = autocommit;
}

inline void command::commit()
{
  close_stmt();
  if (m_autocommit) return;
  m_hnd.check(lib::singleton().p_OCITransCommit(m_hnd.svc, m_hnd.err, OCI_DEFAULT));
} // command::

} } } } // brig::database::oracle::detail