/* {{{ MySQL_ArtResultSetMetaData::getColumnCount() -I- */
unsigned int
MySQL_ArtResultSetMetaData::getColumnCount()
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::getColumnCount");
	CPP_INFO_FMT("this=%p", this);
	CPP_INFO_FMT("column_count=%d", num_fields);
	return num_fields;
}
/* {{{ MySQL_ConstructedResultSetMetaData::getColumnCount() -I- */
unsigned int
MySQL_ConstructedResultSetMetaData::getColumnCount()
{
	CPP_ENTER("MySQL_ConstructedResultSetMetaData::getColumnCount");
	CPP_INFO_FMT("this=%p", this);
	CPP_INFO_FMT("column_count=%d", parent->num_fields);
	return parent->num_fields;
}
/* {{{ MySQL_PreparedResultSetMetaData::getPrecision -I- */
unsigned int
MySQL_PreparedResultSetMetaData::getPrecision(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getPrecision");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	unsigned int ret = getFieldMeta(columnIndex)->max_length - getScale(columnIndex);
	CPP_INFO_FMT("column=%u precision=%d", columnIndex, ret);
	return ret;
}
/* {{{ MySQL_PreparedResultSetMetaData::getScale -I- */
unsigned int
MySQL_PreparedResultSetMetaData::getScale(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getScale");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	unsigned int ret = getFieldMeta(columnIndex)->decimals;
	CPP_INFO_FMT("column=%u scale=%d", columnIndex, ret);
	return ret;
}
/* {{{ MySQL_PreparedResultSetMetaData::getColumnType -I- */
int
MySQL_PreparedResultSetMetaData::getColumnType(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getColumnType");
	CPP_INFO_FMT("this=%p", this);
	CPP_INFO_FMT("column=%u", columnIndex);
	checkColumnIndex(columnIndex);
	int mysql_type = getFieldMeta(columnIndex)->type;
	CPP_INFO_FMT("type=%d", mysql_type);
	int ret = sql::mysql::util::mysql_type_to_datatype(
					getFieldMeta(columnIndex)
				);
	CPP_INFO_FMT("our type is %d", ret);
	return ret;
}
/* {{{ MySQL_Connection::prepareStatement() -I- */
sql::PreparedStatement *
MySQL_Connection::prepareStatement(const sql::SQLString& sql)
{
	CPP_ENTER_WL(intern->logger, "MySQL_Connection::prepareStatement");
	CPP_INFO_FMT("query=%s", sql.c_str());
	checkClosed();
	boost::shared_ptr< NativeAPI::NativeStatementWrapper > stmt;

	//TODO change - probably no need to catch and throw here. Logging can be done inside proxy
	try {
		 stmt.reset(&proxy->stmt_init());
	} catch (sql::SQLException& e) {
		CPP_ERR_FMT("No statement : %d:(%s) %s", proxy->errNo(), proxy->sqlstate().c_str(), proxy->error().c_str());
		throw e;
	}

	if (stmt->prepare(sql)) {
		CPP_ERR_FMT("Cannot prepare %d:(%s) %s", stmt->errNo(), stmt->sqlstate().c_str(), stmt->error().c_str());
		sql::SQLException e(stmt->error(), stmt->sqlstate(), stmt->errNo());
		stmt.reset();
		throw e;
	}

	return new MySQL_Prepared_Statement(stmt, this, intern->defaultPreparedStatementResultType, intern->logger);
}
/* {{{ MySQL_PreparedResultSetMetaData::getColumnCount -I- */
unsigned int
MySQL_PreparedResultSetMetaData::getColumnCount()
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getColumnCount");
	CPP_INFO_FMT("this=%p", this);
	return num_fields;
}
/* {{{ MySQL_PreparedResultSetMetaData::isAutoIncrement -I- */
bool
MySQL_PreparedResultSetMetaData::isAutoIncrement(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isAutoIncrement");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return (getFieldMeta(columnIndex)->flags & AUTO_INCREMENT_FLAG ) != 0;
}
/* {{{ MySQL_PreparedResultSetMetaData::getColumnTypeName -I- */
SQLString
MySQL_PreparedResultSetMetaData::getColumnTypeName(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getColumnTypeName");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return sql::mysql::util::mysql_type_to_string(getFieldMeta(columnIndex), this->logger);
}
/* {{{ MySQL_PreparedResultSetMetaData::getCatalogName -I- */
SQLString
MySQL_PreparedResultSetMetaData::getCatalogName(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getCatalogName");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return getFieldMeta(columnIndex)->catalog;
}
/* {{{ MySQL_PreparedResultSetMetaData::isWritable -I- */
bool
MySQL_PreparedResultSetMetaData::isWritable(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isWritable");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return !isReadOnly(columnIndex);
}
/* {{{ MySQL_PreparedResultSetMetaData::isZerofill -I- */
bool
MySQL_PreparedResultSetMetaData::isZerofill(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isZerofill");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return (getFieldMeta(columnIndex)->flags & ZEROFILL_FLAG) != 0;
}
/* {{{ MySQL_PreparedResultSetMetaData::isSearchable -I- */
bool
MySQL_PreparedResultSetMetaData::isSearchable(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isSearchable");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return true;
}
/* {{{ MySQL_PreparedResultSetMetaData::isNullable -I- */
int
MySQL_PreparedResultSetMetaData::isNullable(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isNullable");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return getFieldMeta(columnIndex)->flags & NOT_NULL_FLAG? columnNoNulls : columnNullable;
}
/* {{{ MySQL_PreparedResultSetMetaData::isCurrency -I- */
bool
MySQL_PreparedResultSetMetaData::isCurrency(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::isCurrency");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return false;
}
/* {{{ MySQL_ArtResultSetMetaData::getCatalogName() -I- */
std::string
MySQL_ArtResultSetMetaData::getCatalogName(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::getCatalogName");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	return "";
}
/* {{{ MySQL_PreparedResultSetMetaData::getColumnDisplaySize -I- */
unsigned int
MySQL_PreparedResultSetMetaData::getColumnDisplaySize(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getColumnDisplaySize");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	const MYSQL_FIELD * const field = getFieldMeta(columnIndex);
	const sql::mysql::util::OUR_CHARSET * const cs = sql::mysql::util::find_charset(field->charsetnr);
	if (!cs) {
		std::ostringstream msg("Server sent uknown charsetnr (");
		msg << field->charsetnr << ") . Please report";
		throw SQLException(msg.str());
	}
	int ret = field->length / cs->char_maxlen;
	CPP_INFO_FMT("column=%u display_size=%d", columnIndex, ret);
	return ret;
}
/* {{{ MySQL_ArtResultSetMetaData::isNullable() -I- */
int
MySQL_ArtResultSetMetaData::isNullable(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::isNullable");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return false;
}
/* {{{ MySQL_ArtResultSetMetaData::isDefinitelyWritable() -I- */
bool
MySQL_ArtResultSetMetaData::isDefinitelyWritable(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::isDefinitelyWritable");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return isWritable(columnIndex);
}
/* {{{ MySQL_ArtResultSetMetaData::isCaseSensitive() -I- */
bool
MySQL_ArtResultSetMetaData::isCaseSensitive(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::isCaseSensitive");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return "true";
}
Example #21
0
 /* {{{ MySQL_ArtResultSet::checkValid() -I- */
 void
 MySQL_ArtResultSet::checkValid() const
 {
     CPP_ENTER("MySQL_ArtResultSet::checkValid");
     CPP_INFO_FMT("this=%p", this);
     if (isClosed()) {
         throw sql::InvalidInstanceException("ResultSet has been closed");
     }
 }
/* {{{ MySQL_ArtResultSetMetaData::~MySQL_ArtResultSetMetaData() -I- */
MySQL_ArtResultSetMetaData::~MySQL_ArtResultSetMetaData()
{
	/* Don't remove the block or we can get into problems with logger */
	{
		CPP_ENTER("MySQL_ArtResultSetMetaData::~MySQL_ArtResultSetMetaData");
		CPP_INFO_FMT("this=%p", this);
	}
	logger->freeReference();
}
/* {{{ MySQL_ArtResultSetMetaData::isZerofill() -I- */
bool
MySQL_ArtResultSetMetaData::isZerofill(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::isZerofill");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return false;
}
/* {{{ MySQL_ArtResultSetMetaData::getColumnType() -I- */
int
MySQL_ArtResultSetMetaData::getColumnType(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::getColumnType");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return sql::DataType::VARCHAR;
}
/* {{{ MySQL_ArtResultSetMetaData::getColumnTypeName() -I- */
SQLString
MySQL_ArtResultSetMetaData::getColumnTypeName(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::getColumnTypeName");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return "VARCHAR";
}
/* {{{ MySQL_PreparedResultSetMetaData::getSchemaName -I- */
SQLString
MySQL_PreparedResultSetMetaData::getSchemaName(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_PreparedResultSetMetaData::getSchemaName");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);
	const char * const db = getFieldMeta(columnIndex)->db;
	return db ? db : "";
}
/* {{{ MySQL_ArtResultSetMetaData::getColumnLabel() -I- */
std::string
MySQL_ArtResultSetMetaData::getColumnLabel(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::getColumnLabel");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	return parent->field_index_to_name_map[columnIndex - 1];
}
/* {{{ MySQL_ConstructedResultSetMetaData::getColumnLabel() -I- */
std::string
MySQL_ConstructedResultSetMetaData::getColumnLabel(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ConstructedResultSetMetaData::getColumnLabel");
	CPP_INFO_FMT("this=%p", this);
	if (columnIndex == 0 || columnIndex > parent->num_fields) {
		throw sql::InvalidArgumentException("Invalid value for columnIndex");
	}
	return parent->field_index_to_name_map[columnIndex - 1];
}
/* {{{ MySQL_ArtResultSetMetaData::getColumnDisplaySize() -U- */
unsigned int
MySQL_ArtResultSetMetaData::getColumnDisplaySize(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::getColumnDisplaySize");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	throw sql::MethodNotImplementedException("MySQL_ArtResultSetMetaData::getColumnDisplaySize()");
	return 0; // This will shut up compilers
}
/* {{{ MySQL_ArtResultSetMetaData::isReadOnly() -I- */
bool
MySQL_ArtResultSetMetaData::isReadOnly(unsigned int columnIndex)
{
	CPP_ENTER("MySQL_ArtResultSetMetaData::isReadOnly");
	CPP_INFO_FMT("this=%p", this);
	checkColumnIndex(columnIndex);

	/* We consider we connect to >= 40100 - else, we can't say */
	return true;
}