Skip to content

Commit 9e8e627

Browse files
committed
- SQL logging channel and archiving strategy
- row formatting refactored - affected row count for insert, delete and update returned from Statement::execute() - internal SQL string formatting capability using Poco::format()
1 parent b57f579 commit 9e8e627

63 files changed

Lines changed: 2555 additions & 336 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Data/Data_VS71.vcproj‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@
247247
<File
248248
RelativePath=".\include\Poco\Data\SessionImpl.h">
249249
</File>
250+
<File
251+
RelativePath=".\include\Poco\Data\SimpleRowFormatter.h">
252+
</File>
250253
<File
251254
RelativePath=".\include\Poco\Data\Statement.h">
252255
</File>
@@ -335,6 +338,9 @@
335338
<File
336339
RelativePath=".\src\SessionImpl.cpp">
337340
</File>
341+
<File
342+
RelativePath=".\src\SimpleRowFormatter.cpp">
343+
</File>
338344
<File
339345
RelativePath=".\src\Statement.cpp">
340346
</File>
@@ -379,6 +385,30 @@
379385
</File>
380386
</Filter>
381387
</Filter>
388+
<Filter
389+
Name="Logging"
390+
Filter="">
391+
<Filter
392+
Name="Header Files"
393+
Filter="">
394+
<File
395+
RelativePath=".\include\Poco\Data\ArchiveStrategy.h">
396+
</File>
397+
<File
398+
RelativePath=".\include\Poco\Data\SQLChannel.h">
399+
</File>
400+
</Filter>
401+
<Filter
402+
Name="Source Files"
403+
Filter="">
404+
<File
405+
RelativePath=".\src\ArchiveStrategy.cpp">
406+
</File>
407+
<File
408+
RelativePath=".\src\SQLChannel.cpp">
409+
</File>
410+
</Filter>
411+
</Filter>
382412
</Files>
383413
<Globals>
384414
</Globals>

‎Data/Data_VS80.vcproj‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@
333333
RelativePath=".\include\Poco\Data\SessionImpl.h"
334334
>
335335
</File>
336+
<File
337+
RelativePath=".\include\Poco\Data\SimpleRowFormatter.h"
338+
>
339+
</File>
336340
<File
337341
RelativePath=".\include\Poco\Data\Statement.h"
338342
>
@@ -449,6 +453,10 @@
449453
RelativePath=".\src\SessionImpl.cpp"
450454
>
451455
</File>
456+
<File
457+
RelativePath=".\src\SimpleRowFormatter.cpp"
458+
>
459+
</File>
452460
<File
453461
RelativePath=".\src\Statement.cpp"
454462
>
@@ -503,6 +511,34 @@
503511
</File>
504512
</Filter>
505513
</Filter>
514+
<Filter
515+
Name="Logging"
516+
>
517+
<Filter
518+
Name="Header Files"
519+
>
520+
<File
521+
RelativePath=".\include\Poco\Data\ArchiveStrategy.h"
522+
>
523+
</File>
524+
<File
525+
RelativePath=".\include\Poco\Data\SQLChannel.h"
526+
>
527+
</File>
528+
</Filter>
529+
<Filter
530+
Name="Source Files"
531+
>
532+
<File
533+
RelativePath=".\src\ArchiveStrategy.cpp"
534+
>
535+
</File>
536+
<File
537+
RelativePath=".\src\SQLChannel.cpp"
538+
>
539+
</File>
540+
</Filter>
541+
</Filter>
506542
</Files>
507543
<Globals>
508544
</Globals>

‎Data/Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
include $(POCO_BASE)/build/rules/global
1010

1111
objects = AbstractBinder AbstractBinding AbstractExtraction \
12-
AbstractExtractor AbstractPreparation AbstractPrepare Bulk \
13-
Connector BLOB BLOBStream DataException Date Limit MetaColumn \
12+
AbstractExtractor AbstractPreparation AbstractPrepare ArchiveStrategy \
13+
Bulk Connector BLOB BLOBStream DataException Date Limit MetaColumn \
1414
PooledSessionHolder PooledSessionImpl Position \
1515
Range RecordSet Row RowFormatter RowIterator \
16-
Session SessionFactory SessionImpl \
17-
SessionPool Statement StatementCreator StatementImpl Time
16+
SimpleRowFormatter Session SessionFactory SessionImpl \
17+
SessionPool SQLChannel Statement StatementCreator StatementImpl Time
1818

1919
target = PocoData
2020
target_version = $(LIBVERSION)

‎Data/ODBC/include/Poco/Data/ODBC/Connector.h‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ class ODBC_API Connector: public Poco::Data::Connector
6060
/// Creates the Connector.
6161

6262
~Connector();
63-
/// Destroys the Connector.
63+
/// Destroys the Connector.
64+
65+
const std::string& name() const;
66+
/// Returns the name associated with this connector.
6467

6568
Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString);
6669
/// Creates a ODBC SessionImpl object and initializes it with the given connectionString.
@@ -73,6 +76,15 @@ class ODBC_API Connector: public Poco::Data::Connector
7376
};
7477

7578

79+
///
80+
/// inlines
81+
///
82+
inline const std::string& Connector::name() const
83+
{
84+
return KEY;
85+
}
86+
87+
7688
} } } // namespace Poco::Data::ODBC
7789

7890

‎Data/ODBC/include/Poco/Data/ODBC/Error.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Error
9292
return str;
9393

9494
std::string s;
95-
format(s,
95+
Poco::format(s,
9696
"===========================\n"
9797
"ODBC Diagnostic record #%d:\n"
9898
"===========================\n"
@@ -112,7 +112,7 @@ class Error
112112
{
113113
std::string str;
114114

115-
format(str,
115+
Poco::format(str,
116116
"Connection:%s\nServer:%s\n",
117117
_diagnostics.connectionName(),
118118
_diagnostics.serverName());

‎Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl
7878
Poco::UInt32 columnsReturned() const;
7979
/// Returns number of columns returned by query.
8080

81+
Poco::UInt32 affectedRowCount() const;
82+
/// Returns the number of affected rows.
83+
/// Used to find out the number of rows affected by insert or update.
84+
8185
const MetaColumn& metaColumn(Poco::UInt32 pos) const;
8286
/// Returns column meta data.
8387

@@ -165,6 +169,7 @@ class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl
165169
int _nextResponse;
166170
ColumnPtrVec _columnPtrs;
167171
bool _prepared;
172+
mutable Poco::UInt32 _affectedRowCount;
168173
};
169174

170175

‎Data/ODBC/src/Binder.cpp‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,22 @@ void Binder::bind(std::size_t pos, const std::string& val, Direction dir)
134134
}
135135
else if (isInBound(dir))
136136
{
137-
pVal = (SQLPOINTER) val.c_str();
137+
if (size) pVal = (SQLPOINTER) val.c_str();
138138
_inParams.insert(ParamMap::value_type(pVal, size));
139139
}
140140
else
141141
throw InvalidArgumentException("Parameter must be [in] OR [out] bound.");
142142

143143
SQLLEN* pLenIn = new SQLLEN;
144-
*pLenIn = SQL_NTS;
144+
if (0 != size) *pLenIn = SQL_NTS;
145+
else
146+
{
147+
*pLenIn = SQL_NULL_DATA;
148+
SQLINTEGER colSize = 0;
149+
SQLSMALLINT decDigits = 0;
150+
getColSizeAndPrecision(pos, SQL_C_CHAR, colSize, decDigits);
151+
size = colSize;
152+
}
145153

146154
if (PB_AT_EXEC == _paramBinding)
147155
*pLenIn = SQL_LEN_DATA_AT_EXEC(size);
@@ -175,7 +183,16 @@ void Binder::bind(std::size_t pos, const BLOB& val, Direction dir)
175183
_inParams.insert(ParamMap::value_type(pVal, size));
176184

177185
SQLLEN* pLenIn = new SQLLEN;
178-
*pLenIn = size;
186+
187+
if (0 != size) *pLenIn = size;
188+
else
189+
{
190+
*pLenIn = SQL_NULL_DATA;
191+
SQLINTEGER colSize = 0;
192+
SQLSMALLINT decDigits = 0;
193+
getColSizeAndPrecision(pos, SQL_C_CHAR, colSize, decDigits);
194+
size = colSize;
195+
}
179196

180197
if (PB_AT_EXEC == _paramBinding)
181198
*pLenIn = SQL_LEN_DATA_AT_EXEC(size);

‎Data/ODBC/src/Connector.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Poco::AutoPtr<Poco::Data::SessionImpl> Connector::createSession(const std::strin
6565

6666
void Connector::registerConnector()
6767
{
68-
Poco::Data::SessionFactory::instance().add(KEY, new Connector());
68+
Poco::Data::SessionFactory::instance().add(new Connector());
6969
}
7070

7171

‎Data/ODBC/src/ODBCMetaColumn.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void ODBCMetaColumn::init()
107107
case SQL_VARCHAR:
108108
case SQL_LONGVARCHAR:
109109
case -9:// SQL Server NVARCHAR
110+
case -10:// PostgreSQL VARCHAR (without size specified)
110111
setType(MetaColumn::FDT_STRING); break;
111112
case SQL_TINYINT:
112113
setType(MetaColumn::FDT_INT8); break;

‎Data/ODBC/src/ODBCStatementImpl.cpp‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ ODBCStatementImpl::ODBCStatementImpl(SessionImpl& rSession):
6464
_stmt(rSession.dbc()),
6565
_stepCalled(false),
6666
_nextResponse(0),
67-
_prepared(false)
67+
_prepared(false),
68+
_affectedRowCount(0)
6869
{
6970
}
7071

@@ -205,6 +206,9 @@ void ODBCStatementImpl::doBind(bool clear, bool reset)
205206
Bindings::iterator it = binds.begin();
206207
Bindings::iterator itEnd = binds.end();
207208

209+
if (it != itEnd && 0 == _affectedRowCount)
210+
_affectedRowCount = static_cast<Poco::UInt32>((*it)->numOfRowsHandled());
211+
208212
if (reset)
209213
{
210214
it = binds.begin();
@@ -257,6 +261,8 @@ void ODBCStatementImpl::clear()
257261
{
258262
SQLRETURN rc = SQLCloseCursor(_stmt);
259263
_stepCalled = false;
264+
_affectedRowCount = 0;
265+
260266
if (Utility::isError(rc))
261267
{
262268
StatementError err(_stmt);
@@ -438,4 +444,17 @@ const MetaColumn& ODBCStatementImpl::metaColumn(Poco::UInt32 pos) const
438444
}
439445

440446

447+
Poco::UInt32 ODBCStatementImpl::affectedRowCount() const
448+
{
449+
if (0 == _affectedRowCount)
450+
{
451+
SQLLEN rows;
452+
if (!Utility::isError(SQLRowCount(_stmt, &rows)))
453+
_affectedRowCount = static_cast<Poco::UInt32>(rows);
454+
}
455+
456+
return _affectedRowCount;
457+
}
458+
459+
441460
} } } // namespace Poco::Data::ODBC

0 commit comments

Comments
 (0)