Version: 1.0.0
mysql_preparedstatement_parameter.cpp
Go to the documentation of this file.
1 #include "wx/database/wxprec.h"
2 
3 #if wxUSE_DATABASE_MYSQL
4 
5 // ctor
8 {
9  m_pBind = pBind;
10  // Default to NULL
11  SetNull();
12 }
13 
14 wxMysqlPreparedStatementParameter::wxMysqlPreparedStatementParameter(MYSQL_BIND* pBind, const wxString& strValue)
16 {
17  m_pBind = pBind;
18  SetString(strValue);
19 }
20 
23 {
24  m_pBind = pBind;
25  SetInt(nValue);
26 }
27 
30 {
31  m_pBind = pBind;
32  SetDouble(dblValue);
33 }
34 
35 wxMysqlPreparedStatementParameter::wxMysqlPreparedStatementParameter(MYSQL_BIND* pBind, const void* pData, long nDataLength)
37 {
38  m_pBind = pBind;
39  SetBlob(pData, nDataLength);
40 }
41 
42 wxMysqlPreparedStatementParameter::wxMysqlPreparedStatementParameter(MYSQL_BIND* pBind, const wxDateTime& dateValue)
44 {
45  m_pBind = pBind;
46  SetDate(dateValue);
47 }
48 
51 {
52  m_pBind = pBind;
53  SetBool(bValue);
54 }
55 
58 {
59  m_pBind = pBind;
60  m_pBind->is_null = &m_bIsNull;
61 
62  // Set the binding properties
63  m_pBind->buffer_type = pField->type;
64  m_pBind->buffer_length = pField->length + 1;
65  //int nType = m_pBind->buffer_type;
66  //if (nType == MYSQL_TYPE_STRING || nType == MYSQL_TYPE_VAR_STRING || nType == MYSQL_TYPE_BLOB
67  // || nType == MYSQL_TYPE_TINY_BLOB || nType == MYSQL_TYPE_MEDIUM_BLOB || nType == MYSQL_TYPE_LONG_BLOB)
68  //{
69  //wxLogDebug(_("Allocating %ld bytes in the MYSQL_BIND buffer\n"), pField->length);
70  void* pBuffer = m_Data.bufferValue.GetWriteBuf(m_pBind->buffer_length);
71  if (pBuffer == 0)
72  {
74  SetErrorMessage(_("Error allocating buffer"));
76  }
77  m_pBind->buffer = pBuffer;
78  ClearBuffer();
79  // }
80  // else
81  // {
82  // pCurrentBinding->buffer = malloc(1);
83  // }
84 
85  int nType = m_pBind->buffer_type;
86  if (nType == MYSQL_TYPE_BLOB || nType == MYSQL_TYPE_TINY_BLOB || nType == MYSQL_TYPE_MEDIUM_BLOB
87  || nType == MYSQL_TYPE_LONG_BLOB)
88  m_pBind->length = &m_Data.nBufferLength;
89 }
90 
91 // dtor
93 {
94 }
95 
97 {
98  if (m_pBind && m_pBind->buffer && (m_pBind->buffer_length > 0))
99  {
100  memset(m_pBind->buffer, 0, m_pBind->buffer_length);
101  }
102 }
103 
105 {
106  m_Data.nValue = nValue;
107  m_pBind->buffer_type = MYSQL_TYPE_LONG;
108  m_pBind->buffer = (void*)&m_Data.nValue;
109 }
110 
112 {
113  m_Data.dblValue = dblValue;
114  m_pBind->buffer_type = MYSQL_TYPE_DOUBLE;
115  m_pBind->buffer = (void*)&m_Data.dblValue;
116 }
117 
118 void wxMysqlPreparedStatementParameter::SetString(const wxString& strValue)
119 {
120  memset(m_pBind, 0, sizeof(MYSQL_BIND));
121  m_Data.strValue = strValue;
122  m_pBind->buffer_type = MYSQL_TYPE_STRING;
124  m_pBind->buffer = (void*)(const char*)m_Data.charBufferValue;
126  m_pBind->length = &(m_Data.nBufferLength);
127  m_pBind->buffer_length = m_Data.nBufferLength;
128 }
129 
131 {
132  m_bIsNull = 1;
133  m_pBind->is_null = &m_bIsNull;
134 }
135 
136 void wxMysqlPreparedStatementParameter::SetBlob(const void* pData, long nDataLength)
137 {
138  void* pBuffer = m_Data.bufferValue.GetWriteBuf(nDataLength);
139  memcpy(pBuffer, pData, nDataLength);
140  m_pBind->buffer_type = MYSQL_TYPE_BLOB;
141  m_pBind->buffer = pBuffer;
142  m_pBind->buffer_length = nDataLength;
143 }
144 
145 void wxMysqlPreparedStatementParameter::SetDate(const wxDateTime& dateValue)
146 {
147  m_Data.dateValue.year = dateValue.GetYear();
148  m_Data.dateValue.month = dateValue.GetMonth();
149  m_Data.dateValue.day = dateValue.GetDay();
150  m_Data.dateValue.hour = dateValue.GetHour();
151  m_Data.dateValue.minute = dateValue.GetMinute();
152  m_Data.dateValue.second = dateValue.GetSecond();
153 
154  m_pBind->buffer_type = MYSQL_TYPE_DATETIME;
155  m_pBind->buffer = (void*)&m_Data.dateValue;
156 }
157 
159 {
160  m_Data.bValue = bValue;
161  m_pBind->buffer_type = MYSQL_TYPE_TINY;
162  m_pBind->buffer = (void*)&m_Data.bValue;
163 }
164 
165 #endif//wxUSE_DATABASE_MYSQL
void SetDate(const wxDateTime &dateValue)
wxMysqlPreparedStatementParameter(MYSQL_BIND *pBind)
void SetString(const wxString &strValue)
void SetBlob(const void *pData, long nDataLength)
void SetErrorMessage(const wxString &strErrorMessage)
void SetDouble(double dblValue)
static int TranslateErrorCode(int nCode)
virtual size_t GetEncodedStreamLength(const wxString &inputString)
void SetErrorCode(int nErrorCode)
virtual const wxCharBuffer ConvertToUnicodeStream(const wxString &inputString)