/* {{{ MySQL_Connection::nativeSQL() -I- */
sql::SQLString
MySQL_Connection::nativeSQL(const sql::SQLString& sql)
{
	CPP_ENTER_WL(intern->logger, "MySQL_Connection::nativeSQL");
	checkClosed();
	return sql::SQLString(sql.c_str());
}
Beispiel #2
0
        /* {{{ MySQL_ArtResultSet::findColumn() -I- */
        uint32_t
        MySQL_ArtResultSet::findColumn(const sql::SQLString& columnLabel) const
        {
            CPP_ENTER("MySQL_ArtResultSet::columnLabel");
            checkValid();

            boost::scoped_array< char > upstring(sql::mysql::util::utf8_strup(columnLabel.c_str(), 0));

            FieldNameIndexMap::const_iterator iter = field_name_to_index_map.find(upstring.get());

            if (iter == field_name_to_index_map.end()) {
                return 0;
            }
            /* findColumn returns 1-based indexes */
            return iter->second + 1;
        }
/* {{{ MySQL_Connection::setSessionVariable() -I- */
void
MySQL_Connection::setSessionVariable(const sql::SQLString & varname, const sql::SQLString & value)
{
	CPP_ENTER_WL(intern->logger, "MySQL_Connection::setSessionVariable");
	checkClosed();

	sql::SQLString q("SET SESSION ");
	q.append(varname).append("=");

	if (!value.compare("NULL")) {
		q.append("NULL");
	} else {
		q.append("'").append(value).append("'");
	}

	service->executeUpdate(q);
	if (intern->cache_sql_mode && !strncasecmp(varname.c_str(), "sql_mode", sizeof("sql_mode") - 1)) {
		intern->sql_mode= value;
	}
}
/* {{{ MySQL_Uri::setHost() -I- */
void MySQL_Uri::setHost(const sql::SQLString &h)
{
  setProtocol(NativeAPI::PROTOCOL_TCP);
  host= h.c_str();
}
/* URI formats tcp://[host]:port/schema
               unix://socket
               pipe://named_pipe
 */
bool parseUri(const sql::SQLString & str, MySQL_Uri& uri)
{
  if (!str.compare(0, sizeof(MYURI_SOCKET_PREFIX) - 1, MYURI_SOCKET_PREFIX))
  {
    uri.setSocket(str.substr(sizeof(MYURI_SOCKET_PREFIX) - 1, sql::SQLString::npos));

    return true;
  }

  if (!str.compare(0, sizeof(MYURI_PIPE_PREFIX) - 1 , MYURI_PIPE_PREFIX))
  {
    uri.setPipe(str.substr(sizeof(MYURI_PIPE_PREFIX) - 1, sql::SQLString::npos));

    return true;
  }

  sql::SQLString host;
  size_t start_sep, end_sep;

  /* i wonder how did it work with "- 1"*/
  if (!str.compare(0, sizeof(MYURI_TCP_PREFIX) - 1, MYURI_TCP_PREFIX) )
  {
    host= str.substr(sizeof(MYURI_TCP_PREFIX) - 1, sql::SQLString::npos);
  }
  else
  {
    /* allowing to have port and schema specified even w/out protocol
       specifier("tcp://") */
    host= str.c_str();
  }

  if (host[0] == MYURI_HOST_BEGIN)
  {
    end_sep= host.find(MYURI_HOST_END);

    /* No closing ] after [*/
    if (end_sep == sql::SQLString::npos)
    {
      return false;
    }

    uri.setHost(host.substr(1, end_sep - 1));
    /* Cutting host to continue w/ port and schema reading */
    host= host.substr(end_sep + 1);
  }

  /* Looking where schema part begins */
  start_sep = host.find('/');

  if (start_sep != sql::SQLString::npos)
  {
    if ((host.length() - start_sep) > 1/*Slash*/)
    {
      uri.setSchema(host.substr(start_sep + 1, host.length() - start_sep - 1));
    }

    host= host.substr(0, start_sep);
  }
  else
  {
    uri.setSchema("");
  }

  /* Looking where port part begins*/
  start_sep = host.find_last_of(':', sql::SQLString::npos);

  if (start_sep != sql::SQLString::npos)
  {
    uri.setPort(atoi(host.substr(start_sep + 1, sql::SQLString::npos).c_str()));
    host = host.substr(0, start_sep);
  }
  else
  {
    uri.setPort(DEFAULT_TCP_PORT);
  }

  /* If host was enclosed in [], it has been already set, and "host" variable is
     empty */
  if (host.length() > 0)
  {
    uri.setHost(host);
  }

  return true;
}
/* {{{ MySQL_Uri::setPipe() -I- */
void MySQL_Uri::setPipe(const sql::SQLString &p)
{
  setProtocol(NativeAPI::PROTOCOL_PIPE);
  host= p.c_str();
}
/* {{{ MySQL_Uri::setSocket() -I- */
void MySQL_Uri::setSocket(const sql::SQLString &s)
{
  setProtocol(NativeAPI::PROTOCOL_SOCKET);
  host= s.c_str();
}
/* {{{ MySQL_NativeStatementWrapper::prepare() */
int
MySQL_NativeStatementWrapper::prepare(const ::sql::SQLString & stmt_str)
{
    return api->stmt_prepare(stmt, stmt_str.c_str(), stmt_str.length());
}