Tag: cws_src680_sqlite User: aklitzing Date: 2006/09/04 15:28:33 Modified: dba/connectivity/source/drivers/sqlite3/sqPrepare.cpp dba/connectivity/source/drivers/sqlite3/sqPrepare.h
Log: * setInteger added * some changes to a clean interface File Changes: Directory: /dba/connectivity/source/drivers/sqlite3/ ==================================================== File [changed]: sqPrepare.cpp Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/sqlite3/sqPrepare.cpp?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +59 -32 --------------------- --- sqPrepare.cpp 29 Aug 2006 22:22:22 -0000 1.1.2.2 +++ sqPrepare.cpp 4 Sep 2006 22:28:30 -0000 1.1.2.3 @@ -2,9 +2,9 @@ * * $RCSfile: sqPrepare.cpp,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: aklitzing $ $Date: 2006/08/29 22:22:22 $ + * last change: $Author: aklitzing $ $Date: 2006/09/04 22:28:30 $ * * Original author: André Klitzing * @@ -34,7 +34,7 @@ ************************************************************************/ #include "sqPrepare.h" -#include "string.h" // only for strlen() and strncpy() +#include <string.h> // only for strlen() and strncpy() // ---------------------------------------------------------------------- // CTor, DTor, Operators @@ -146,23 +146,21 @@ void sqPrepare::setText(int _index, const char* _value, const char _quote) { setNull(_index); // try to delete old value to avoid memory leaks - --_index; // first param is 0, second param is 1 + m_paramBind[--_index] = copyString(_value, _quote); +} - char* newValue; - if(_quote == '\0') - newValue = copyString(_value); - else - { - int len = strlen(_value); - newValue = new char[len+3]; // 1 byte for NULL-Termination and 2 bytes for _quote at both sides - strncpy(newValue+1, _value, len); // copy only the string and reserve space for the quotes - newValue[0] = _quote; // set the first quote - newValue[len+1] = _quote; // set the second quote - newValue[len+2] = '\0'; // set the null-termination - } +void sqPrepare::setInteger(int _index, int _value, const char _quote) +{ + setNull(_index); // try to delete old value to avoid memory leaks + --_index; // first param is 0, second param is 1 - m_paramBind[_index] = newValue; + char* buffer = new char[33]; + intToChar(_value, buffer); + if(_quote == '\0') // avoid unneeded extra copy - we can use our buffer + m_paramBind[_index] = buffer; + else + m_paramBind[_index] = copyString(buffer, _quote); } @@ -175,11 +173,30 @@ } -/* TODO -void setInteger(int _index, int _value); -int setInteger64(int _index, long long int _value); -int setDouble(int _index, double _value); -*/ +// Service Functions + +char* sqPrepare::copyString(const char* _string, const char _quote) +{ + int len = strlen(_string); + char* newString; + if(_quote == '\0') + { + newString = new char[len+1]; + strncpy(newString, _string, len); + newString[len] = '\0'; + } + else + { + newString = new char[len+3]; // 1 byte for NULL-Termination and 2 bytes for _quote at both sides + strncpy(newString+1, _string, len); // copy only the string and reserve space for the quotes + + newString[0] = _quote; // set the first quote + newString[len+1] = _quote; // set the second quote + newString[len+2] = '\0'; // set the null-termination + } + return newString; +} + @@ -187,6 +204,26 @@ // protected // ---------------------------------------------------------------------- +void sqPrepare::intToChar(int _value, char* _buffer) const +{ + if(_value < 0) + { + _value *= -1; + _buffer[0] = '-'; + ++_buffer; + } + + int len = 0, tmp = _value; + + while(tmp/=10) + ++len; + + for(int i=len; 0 <= i; --i, _value /= 10) + _buffer[i] = '0' + (_value % 10); + + _buffer[len+1] = '\0'; +} + void sqPrepare::writeBindStr(char* _newStr, int& _newStrPos, int& _oldStrPos, const char* _fromBind) const { ++_oldStrPos; // we only need to jump ONE (the ?) char... but derived classes needs maybe a higher jump @@ -194,16 +231,6 @@ for(int i=0; source[i] != '\0'; ++i) // copy the binding _newStr[_newStrPos++] = source[i]; -} - - -char* sqPrepare::copyString(const char* _string) -{ - int len = strlen(_string); - char* newQuery = new char[len+1]; - strncpy(newQuery, _string, len); - newQuery[len] = '\0'; - return newQuery; } File [changed]: sqPrepare.h Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/sqlite3/sqPrepare.h?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +17 -10 --------------------- --- sqPrepare.h 29 Aug 2006 22:22:22 -0000 1.1.2.2 +++ sqPrepare.h 4 Sep 2006 22:28:30 -0000 1.1.2.3 @@ -2,9 +2,9 @@ * * $RCSfile: sqPrepare.h,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: aklitzing $ $Date: 2006/08/29 22:22:22 $ + * last change: $Author: aklitzing $ $Date: 2006/09/04 22:28:30 $ * * Original author: André Klitzing * @@ -81,14 +81,14 @@ //! \param _paramNumber the 'position' in m_paramPos //! \param _posInString the 'position' in m_string of the m_wildcard void parser(unsigned short _paramNumber=0, unsigned short _posInString=0); - + void setBind(); protected: - //! \brief it will copy the given string and returns a pointer to it (only a service function) - //! \param _string the string you want to copy - //! \return the copy of your given string. You have the ownership! - char* copyString(const char* _string); + //! \brief it will write the _value from integer to the given _buffer as char (only a service function) + //! \param _value the integer you want to convert + //! \param _buffer the buffer that will be written... it should be big enough! + void intToChar(int _value, char* _buffer) const; //! \brief it will set m_paramCount and create space for the bindings /*! @@ -204,14 +204,21 @@ //! \return nothing void setText(int _index, const char* _value, const char _quote='\0'); + void setInteger(int _index, int _value, const char _quote='\0'); + //! \brief reset the given _index to NULL. The old copied _value will be freed //! \param _index number of the parameter in the prepared string. First param is 1, second param is 2... //! \return nothing void setNull(int _index); -// void setInteger(int _index, int _value); -// int setInteger64(int _index, long long int _value); -// int setDouble(int _index, double _value); + + // Service Functions + + //! \brief it will copy the given string and returns a pointer to it (only a service function) + //! \param _string the string you want to copy + //! \param _quote a char that will be used as 'quotes'. (Default: '\0' means NO quote) + //! \return the copy of your given string. You have the ownership! + static char* copyString(const char* _string, const char _quote='\0'); }; #endif // __SQLITE3s_SQPREPARE_H --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
