Example #1
0
DBType MyBoundResults::GetFieldType(unsigned int field)
{
	if (field >= m_ColCount)
	{
		return DBType_Unknown;
	}

	MYSQL_FIELD *fld = mysql_fetch_field_direct(m_pRes, field);
	return GetOurType(fld->type);
}
Example #2
0
	bool MyBoundResults::Initialize()
	{
		/* Check if we need to build our result binding information */
		if (!m_Initialized)
		{
			for (unsigned int i = 0; i < m_ColCount; i++)
			{
				MYSQL_FIELD *field = mysql_fetch_field_direct(m_pRes, i);
				DBType type = GetOurType(field->type);

				m_bind[i].length = &(m_pull[i].my_length);
				m_bind[i].is_null = &(m_pull[i].my_null);

				if (type == DBType_Integer)
				{
					m_bind[i].buffer_type = MYSQL_TYPE_LONG;
					m_bind[i].buffer = &(m_pull[i].data.ival);
				}
				else if (type == DBType_Float) {
					m_bind[i].buffer_type = MYSQL_TYPE_FLOAT;
					m_bind[i].buffer = &(m_pull[i].data.ival);
				}
				else if (type == DBType_String || type == DBType_Blob) {
					m_bind[i].buffer_type = GetTheirType(type);

					/* We bound this to 2048 bytes.  Otherwise a MEDIUMBLOB
					 * or something could allocate horrible amounts of memory
					 * because MySQL is incompetent.
					 */
					size_t creat_length = (size_t)field->length;
					if (!creat_length || creat_length > DEFAULT_BUFFER_SIZE)
					{
						creat_length = DEFAULT_BUFFER_SIZE;
					}
					m_pull[i].blob = new unsigned char[creat_length];
					m_pull[i].length = creat_length;

					m_bind[i].buffer = m_pull[i].blob;
					m_bind[i].buffer_length = (unsigned long)creat_length;
				}
				else {
					return false;
				}
			}
			m_Initialized = true;
		}

		/* Do the actual bind */
		return (mysql_stmt_bind_result(m_stmt, m_bind) == 0);
	}