mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
0-based col/row, RecordSet metadata, Tuple sample
This commit is contained in:
parent
a768c2e791
commit
6027101fa6
@ -178,10 +178,12 @@ inline bool ODBCStatementImpl::nextRowReady() const
|
||||
|
||||
inline const MetaColumn& ODBCStatementImpl::metaColumn(Poco::UInt32 pos) const
|
||||
{
|
||||
if (pos > _columnPtrs.size())
|
||||
std::size_t sz = _columnPtrs.size();
|
||||
|
||||
if (0 == sz || pos > sz - 1)
|
||||
throw InvalidAccessException(format("Invalid column number: %u", pos));
|
||||
|
||||
return *_columnPtrs[pos-1];
|
||||
return *_columnPtrs[pos];
|
||||
}
|
||||
|
||||
|
||||
|
@ -66,7 +66,7 @@ void ODBCColumn::getDescription()
|
||||
_columnDesc.isNullable = 0;
|
||||
|
||||
if (Utility::isError(SQLDescribeCol(_rStmt,
|
||||
(SQLUSMALLINT) position(),
|
||||
(SQLUSMALLINT) position() + 1, // ODBC columns are 1-based
|
||||
_columnDesc.name,
|
||||
NAME_BUFFER_LENGTH,
|
||||
&_columnDesc.nameBufferLength,
|
||||
@ -85,7 +85,7 @@ void ODBCColumn::init()
|
||||
getDescription();
|
||||
|
||||
if (Utility::isError(SQLColAttribute(_rStmt,
|
||||
(SQLUSMALLINT) position(),
|
||||
(SQLUSMALLINT) position() + 1, // ODBC columns are 1-based
|
||||
SQL_DESC_LENGTH,
|
||||
0,
|
||||
0,
|
||||
|
@ -315,7 +315,7 @@ void ODBCStatementImpl::fillColumns()
|
||||
{
|
||||
Poco::UInt32 colCount = columnsReturned();
|
||||
|
||||
for (int i = 1; i <= colCount; ++i)
|
||||
for (int i = 0; i < colCount; ++i)
|
||||
_columnPtrs.push_back(new ODBCColumn(_stmt, i));
|
||||
}
|
||||
|
||||
|
@ -1585,32 +1585,32 @@ void SQLExecutor::internalExtraction()
|
||||
assert (3 == rset2.columnCount());
|
||||
assert (4 == rset2.rowCount());
|
||||
|
||||
int i = rset.value<int>(1,1);
|
||||
int i = rset.value<int>(0,0);
|
||||
assert (1 == i);
|
||||
|
||||
std::string s = rset.value(1,1);
|
||||
std::string s = rset.value(0,0);
|
||||
assert ("1" == s);
|
||||
|
||||
int a = rset.value<int>(1,3);
|
||||
int a = rset.value<int>(0,2);
|
||||
assert (3 == a);
|
||||
|
||||
try
|
||||
{
|
||||
double d = rset.value<double>(2,2);
|
||||
double d = rset.value<double>(1,1);
|
||||
assert (2.5 == d);
|
||||
}
|
||||
catch (BadCastException&)
|
||||
{
|
||||
float f = rset.value<float>(2,2);
|
||||
float f = rset.value<float>(1,1);
|
||||
assert (2.5 == f);
|
||||
}
|
||||
|
||||
s = rset.value<std::string>(3,3);
|
||||
s = rset.value<std::string>(2,2);
|
||||
assert ("5" == s);
|
||||
i = rset.value("str0", 3);
|
||||
i = rset.value("str0", 2);
|
||||
assert (5 == i);
|
||||
|
||||
const Column<int>& col = rset.column<int>(1);
|
||||
const Column<int>& col = rset.column<int>(0);
|
||||
Column<int>::Iterator it = col.begin();
|
||||
Column<int>::Iterator end = col.end();
|
||||
for (int i = 1; it != end; ++it, ++i)
|
||||
@ -1622,7 +1622,7 @@ void SQLExecutor::internalExtraction()
|
||||
try
|
||||
{
|
||||
//this is what most drivers will return
|
||||
int i = rset.value<int>(1,1);
|
||||
int i = rset.value<int>(0,0);
|
||||
assert (4 == i);
|
||||
}
|
||||
catch(BadCastException&)
|
||||
@ -1630,30 +1630,30 @@ void SQLExecutor::internalExtraction()
|
||||
try
|
||||
{
|
||||
//this is for Oracle
|
||||
double i = rset.value<double>(1,1);
|
||||
double i = rset.value<double>(0,0);
|
||||
assert (4 == int(i));
|
||||
}
|
||||
catch(BadCastException&)
|
||||
{
|
||||
//this is for PostgreSQL
|
||||
Poco::Int64 big = rset.value<Poco::Int64>(1,1);
|
||||
Poco::Int64 big = rset.value<Poco::Int64>(0,0);
|
||||
assert (4 == big);
|
||||
}
|
||||
}
|
||||
|
||||
s = rset.value("cnt", 1).convert<std::string>();
|
||||
s = rset.value("cnt", 0).convert<std::string>();
|
||||
assert ("4" == s);
|
||||
|
||||
try { const Column<int>& col1 = rset.column<int>(100); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
|
||||
try { rset.value<std::string>(1,1); fail ("must fail"); }
|
||||
try { rset.value<std::string>(0,0); fail ("must fail"); }
|
||||
catch (BadCastException&) { }
|
||||
|
||||
stmt = (*_pSession << "DELETE FROM Vectors", now);
|
||||
rset = stmt;
|
||||
|
||||
try { const Column<int>& col1 = rset.column<int>(1); fail ("must fail"); }
|
||||
try { const Column<int>& col1 = rset.column<int>(0); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
}
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail (funct); }
|
||||
|
@ -116,7 +116,7 @@ void SQLiteStatementImpl::compileImpl()
|
||||
|
||||
for (int i = 0; i < colCount; ++i)
|
||||
{
|
||||
MetaColumn mc(i + 1, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
|
||||
MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
|
||||
_columns.push_back(mc);
|
||||
}
|
||||
}
|
||||
@ -225,8 +225,8 @@ Poco::UInt32 SQLiteStatementImpl::columnsReturned() const
|
||||
|
||||
const MetaColumn& SQLiteStatementImpl::metaColumn(Poco::UInt32 pos) const
|
||||
{
|
||||
poco_assert (pos > 0 && pos <= _columns.size());
|
||||
return _columns[pos-1];
|
||||
poco_assert (pos >= 0 && pos <= _columns.size());
|
||||
return _columns[pos];
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size
|
||||
{
|
||||
poco_assert_dbg (pStmt);
|
||||
|
||||
const char* pc = sqlite3_column_decltype(pStmt, (int)pos);
|
||||
const char* pc = sqlite3_column_decltype(pStmt, (int) pos);
|
||||
std::string sqliteType = pc ? pc : "";
|
||||
Poco::toUpperInPlace(sqliteType);
|
||||
|
||||
|
@ -1567,25 +1567,25 @@ void SQLiteTest::testInternalExtraction()
|
||||
assert (3 == rset2.columnCount());
|
||||
assert (4 == rset2.rowCount());
|
||||
|
||||
int a = rset.value<int>(1,3);
|
||||
int a = rset.value<int>(0,2);
|
||||
assert (3 == a);
|
||||
|
||||
int b = rset2.value<int>("InT0",3);
|
||||
int b = rset2.value<int>("InT0",2);
|
||||
assert (3 == b);
|
||||
|
||||
double d = rset.value<double>(2,1);
|
||||
double d = rset.value<double>(1,0);
|
||||
assert (1.5 == d);
|
||||
|
||||
std::string s = rset.value<std::string>(3,2);
|
||||
std::string s = rset.value<std::string>(2,1);
|
||||
assert ("4" == s);
|
||||
|
||||
const Column<int>& col = rset.column<int>(1);
|
||||
assert (col[1] == 1);
|
||||
const Column<int>& col = rset.column<int>(0);
|
||||
assert (col[0] == 1);
|
||||
|
||||
try { const Column<int>& col1 = rset.column<int>(100); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
|
||||
const Column<int>& col1 = rset.column<int>(1);
|
||||
const Column<int>& col1 = rset.column<int>(0);
|
||||
assert ("int0" == col1.name());
|
||||
Column<int>::Iterator it = col1.begin();
|
||||
Column<int>::Iterator itEnd = col1.end();
|
||||
@ -1594,13 +1594,13 @@ void SQLiteTest::testInternalExtraction()
|
||||
assert (counter == *it);
|
||||
|
||||
rset = (tmp << "SELECT COUNT(*) FROM Vectors", now);
|
||||
s = rset.value<std::string>(1,1);
|
||||
s = rset.value<std::string>(0,0);
|
||||
assert ("4" == s);
|
||||
|
||||
stmt = (tmp << "DELETE FROM Vectors", now);
|
||||
rset = stmt;
|
||||
|
||||
try { const Column<int>& col1 = rset.column<int>(1); fail ("must fail"); }
|
||||
try { const Column<int>& col1 = rset.column<int>(0); fail ("must fail"); }
|
||||
catch (RangeException&) { }
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pData->at(row-1);
|
||||
return _pData->at(row);
|
||||
}
|
||||
catch (std::out_of_range& ex)
|
||||
{
|
||||
@ -174,6 +174,8 @@ public:
|
||||
return _pData->end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
Column();
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace Data {
|
||||
|
||||
class Data_API RecordSet: private Statement
|
||||
/// RecordSet class provides access to data returned from a query.
|
||||
/// Data access indexes (row and column) are 1-based.
|
||||
/// Data access indexes (row and column) are 0-based.
|
||||
/// Recordset provides navigation methods to iterate through the
|
||||
/// recordset and retrieval methods to extract data.
|
||||
{
|
||||
@ -90,10 +90,11 @@ public:
|
||||
|
||||
const AbstractExtractionVec& rExtractions = extractions();
|
||||
|
||||
if (pos > rExtractions.size())
|
||||
std::size_t s = rExtractions.size();
|
||||
if (0 == s || pos > s - 1)
|
||||
throw RangeException(format("Invalid column number: %z", pos));
|
||||
|
||||
ExtractionVecPtr pExtraction = dynamic_cast<ExtractionVecPtr>(rExtractions[pos - 1].get());
|
||||
ExtractionVecPtr pExtraction = dynamic_cast<ExtractionVecPtr>(rExtractions[pos].get());
|
||||
|
||||
if (pExtraction)
|
||||
{
|
||||
@ -151,6 +152,29 @@ public:
|
||||
DynamicAny operator [] (std::size_t index);
|
||||
/// Returns the value in the named column of the current row.
|
||||
|
||||
MetaColumn::ColumnDataType columnType(std::size_t pos) const;
|
||||
/// Returns the type for the column at specified position.
|
||||
|
||||
MetaColumn::ColumnDataType columnType(const std::string& name) const;
|
||||
/// Returns the type for the column with specified name.
|
||||
|
||||
const std::string& columnName(std::size_t pos) const;
|
||||
/// Returns column name for the column at specified position.
|
||||
|
||||
std::size_t columnLength(std::size_t pos) const;
|
||||
/// Returns column maximum length for the column at specified position.
|
||||
|
||||
std::size_t columnLength(const std::string& name) const;
|
||||
/// Returns column maximum length for the column with specified name.
|
||||
|
||||
std::size_t columnPrecision(std::size_t pos) const;
|
||||
/// Returns column precision for the column at specified position.
|
||||
/// Valid for floating point fields only (zero for other data types).
|
||||
|
||||
std::size_t columnPrecision(const std::string& name) const;
|
||||
/// Returns column precision for the column with specified name.
|
||||
/// Valid for floating point fields only (zero for other data types).
|
||||
|
||||
private:
|
||||
RecordSet();
|
||||
|
||||
@ -185,6 +209,8 @@ private:
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
|
||||
|
||||
inline std::size_t RecordSet::rowCount() const
|
||||
{
|
||||
poco_assert (extractions().size());
|
||||
@ -229,6 +255,48 @@ inline DynamicAny RecordSet::operator [] (std::size_t index)
|
||||
}
|
||||
|
||||
|
||||
inline MetaColumn::ColumnDataType RecordSet::columnType(std::size_t pos)const
|
||||
{
|
||||
return metaColumn(static_cast<UInt32>(pos)).type();
|
||||
}
|
||||
|
||||
|
||||
inline MetaColumn::ColumnDataType RecordSet::columnType(const std::string& name)const
|
||||
{
|
||||
return metaColumn(name).type();
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& RecordSet::columnName(std::size_t pos) const
|
||||
{
|
||||
return metaColumn(static_cast<UInt32>(pos)).name();
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t RecordSet::columnLength(std::size_t pos) const
|
||||
{
|
||||
return metaColumn(static_cast<UInt32>(pos)).length();
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t RecordSet::columnLength(const std::string& name)const
|
||||
{
|
||||
return metaColumn(name).length();
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t RecordSet::columnPrecision(std::size_t pos) const
|
||||
{
|
||||
return metaColumn(static_cast<UInt32>(pos)).precision();
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t RecordSet::columnPrecision(const std::string& name)const
|
||||
{
|
||||
return metaColumn(name).precision();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
|
@ -135,10 +135,10 @@ protected:
|
||||
const AbstractExtractionVec& extractions() const;
|
||||
/// Returns the extractions vector.
|
||||
|
||||
MetaColumn::ColumnDataType columnType(std::size_t pos) const;
|
||||
const MetaColumn& metaColumn(std::size_t pos) const;
|
||||
/// Returns the type for the column at specified position.
|
||||
|
||||
MetaColumn::ColumnDataType columnType(const std::string& name) const;
|
||||
inline const MetaColumn& metaColumn(const std::string& name) const;
|
||||
/// Returns the type for the column with specified name.
|
||||
|
||||
private:
|
||||
@ -206,15 +206,14 @@ inline const AbstractExtractionVec& Statement::extractions() const
|
||||
}
|
||||
|
||||
|
||||
inline MetaColumn::ColumnDataType Statement::columnType(std::size_t pos)const
|
||||
inline const MetaColumn& Statement::metaColumn(std::size_t pos) const
|
||||
{
|
||||
return (_ptr->metaColumn(static_cast<UInt32>(pos))).type();
|
||||
return _ptr->metaColumn(static_cast<UInt32>(pos));
|
||||
}
|
||||
|
||||
|
||||
inline MetaColumn::ColumnDataType Statement::columnType(const std::string& name)const
|
||||
inline const MetaColumn& Statement::metaColumn(const std::string& name) const
|
||||
{
|
||||
return (_ptr->metaColumn(name)).type();
|
||||
return _ptr->metaColumn(name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -216,6 +216,8 @@ private:
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline void StatementImpl::addBinding(AbstractBinding* info)
|
||||
{
|
||||
_bindings.push_back(info);
|
||||
|
17
Data/samples/Tuple/Makefile
Normal file
17
Data/samples/Tuple/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/Data/samples/Tuple/Makefile#1 $
|
||||
#
|
||||
# Makefile for Poco Data Tuple sample
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = Binding
|
||||
|
||||
target = Tuple
|
||||
target_version = 1
|
||||
target_libs = PocoFoundation PocoData PocoSQLite
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
147
Data/samples/Tuple/Tuple_vs71.vcproj
Normal file
147
Data/samples/Tuple/Tuple_vs71.vcproj
Normal file
@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="Binding"
|
||||
ProjectGUID="{F2972327-DCA7-49BB-B55D-66C554CF1205}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\Data\include;..\..\..\Data\SQLite\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="bin/Bindingd.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/Bindingd.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\Data\include;..\..\..\Data\SQLite\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="bin/Binding.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\Binding.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
209
Data/samples/Tuple/Tuple_vs80.vcproj
Normal file
209
Data/samples/Tuple/Tuple_vs80.vcproj
Normal file
@ -0,0 +1,209 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="Tuple"
|
||||
ProjectGUID="{79D784CB-663C-444E-BCB2-1A1166D19DFB}"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\Data\include;..\..\..\Data\SQLite\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="bin/Tupled.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="bin/Tupled.pdb"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;..\..\..\Foundation\include;..\..\..\Data\include;..\..\..\Data\SQLite\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="bin/Tuple.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Tuple.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
73
Data/samples/Tuple/src/Tuple.cpp
Normal file
73
Data/samples/Tuple/src/Tuple.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// Tuple.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/samples/Tuple/src/Tuple.cpp#1 $
|
||||
//
|
||||
// This sample demonstrates the Data library.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This is unpublished proprietary source code of Applied Informatics
|
||||
// Software Engineering GmbH.
|
||||
// The contents of this file may not be disclosed to third parties,
|
||||
// copied or duplicated in any form, in whole or in part, without
|
||||
// prior written permission from Applied Informatics.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Tuple.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
typedef Poco::Tuple<std::string, std::string, int> Person;
|
||||
typedef std::vector<Person> People;
|
||||
|
||||
// register SQLite connector
|
||||
Poco::Data::SQLite::Connector::registerConnector();
|
||||
|
||||
// create a session
|
||||
Session session("SQLite", "sample.db");
|
||||
|
||||
// drop sample table, if it exists
|
||||
session << "DROP TABLE IF EXISTS Person", now;
|
||||
|
||||
// (re)create table
|
||||
session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3))", now;
|
||||
|
||||
// insert some rows
|
||||
People people;
|
||||
people.push_back(Person("Bart Simpson", "Springfield", 12));
|
||||
people.push_back(Person("Lisa Simpson", "Springfield", 10));
|
||||
|
||||
Statement insert(session);
|
||||
insert << "INSERT INTO Person VALUES(:name, :address, :age)",
|
||||
use(people), now;
|
||||
|
||||
people.clear();
|
||||
|
||||
// a simple query
|
||||
Statement select(session);
|
||||
select << "SELECT Name, Address, Age FROM Person",
|
||||
into(people),
|
||||
now;
|
||||
|
||||
for (People::const_iterator it = people.begin(); it != people.end(); ++it)
|
||||
{
|
||||
std::cout << "Name: " << it->get<0>() <<
|
||||
", Address: " << it->get<1>() <<
|
||||
", Age: " << it->get<2>() <<std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TypeHandler", "TypeHandler\
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RecordSet", "RecordSet\RecordSet_vs80.vcproj", "{56F66D36-F11E-4AA1-AD37-4518A253059D}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tuple", "Tuple\Tuple_vs80.vcproj", "{79D784CB-663C-444E-BCB2-1A1166D19DFB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
debug_shared|Win32 = debug_shared|Win32
|
||||
@ -25,6 +27,10 @@ Global
|
||||
{56F66D36-F11E-4AA1-AD37-4518A253059D}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{56F66D36-F11E-4AA1-AD37-4518A253059D}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
{79D784CB-663C-444E-BCB2-1A1166D19DFB}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{79D784CB-663C-444E-BCB2-1A1166D19DFB}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{79D784CB-663C-444E-BCB2-1A1166D19DFB}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{79D784CB-663C-444E-BCB2-1A1166D19DFB}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -59,7 +59,7 @@ MetaColumn::MetaColumn(std::size_t position,
|
||||
_type(type),
|
||||
_nullable(nullable)
|
||||
{
|
||||
poco_assert(position > 0);
|
||||
poco_assert(position >= 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace Data {
|
||||
|
||||
RecordSet::RecordSet(const Statement& rStatement):
|
||||
Statement(rStatement),
|
||||
_currentRow(1)
|
||||
_currentRow(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -81,18 +81,18 @@ DynamicAny RecordSet::value(const std::string& name, std::size_t row) const
|
||||
switch (columnType(name))
|
||||
{
|
||||
case MetaColumn::FDT_BOOL:
|
||||
case MetaColumn::FDT_INT8: return value<Int8>(name, row); break;
|
||||
case MetaColumn::FDT_UINT8: return value<UInt8>(name, row); break;
|
||||
case MetaColumn::FDT_INT16: return value<Int16>(name, row); break;
|
||||
case MetaColumn::FDT_UINT16: return value<UInt16>(name, row); break;
|
||||
case MetaColumn::FDT_INT32: return value<Int32>(name, row); break;
|
||||
case MetaColumn::FDT_UINT32: return value<UInt32>(name, row); break;
|
||||
case MetaColumn::FDT_INT64: return value<Int64>(name, row); break;
|
||||
case MetaColumn::FDT_UINT64: return value<UInt64>(name, row); break;
|
||||
case MetaColumn::FDT_FLOAT: return value<float>(name, row); break;
|
||||
case MetaColumn::FDT_DOUBLE: return value<double>(name, row); break;
|
||||
case MetaColumn::FDT_STRING: return value<std::string>(name, row); break;
|
||||
case MetaColumn::FDT_BLOB: return value<BLOB>(name, row); break;
|
||||
case MetaColumn::FDT_INT8: return value<Int8>(name, row);
|
||||
case MetaColumn::FDT_UINT8: return value<UInt8>(name, row);
|
||||
case MetaColumn::FDT_INT16: return value<Int16>(name, row);
|
||||
case MetaColumn::FDT_UINT16: return value<UInt16>(name, row);
|
||||
case MetaColumn::FDT_INT32: return value<Int32>(name, row);
|
||||
case MetaColumn::FDT_UINT32: return value<UInt32>(name, row);
|
||||
case MetaColumn::FDT_INT64: return value<Int64>(name, row);
|
||||
case MetaColumn::FDT_UINT64: return value<UInt64>(name, row);
|
||||
case MetaColumn::FDT_FLOAT: return value<float>(name, row);
|
||||
case MetaColumn::FDT_DOUBLE: return value<double>(name, row);
|
||||
case MetaColumn::FDT_STRING: return value<std::string>(name, row);
|
||||
case MetaColumn::FDT_BLOB: return value<BLOB>(name, row);
|
||||
default:
|
||||
throw Poco::InvalidArgumentException("Data type not supported.");
|
||||
}
|
||||
@ -103,7 +103,7 @@ bool RecordSet::moveFirst()
|
||||
{
|
||||
if (rowCount() > 0)
|
||||
{
|
||||
_currentRow = 1;
|
||||
_currentRow = 0;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
@ -112,7 +112,7 @@ bool RecordSet::moveFirst()
|
||||
|
||||
bool RecordSet::moveNext()
|
||||
{
|
||||
if (_currentRow >= rowCount()) return false;
|
||||
if (_currentRow >= rowCount() - 1) return false;
|
||||
++_currentRow;
|
||||
return true;
|
||||
}
|
||||
@ -120,7 +120,7 @@ bool RecordSet::moveNext()
|
||||
|
||||
bool RecordSet::movePrevious()
|
||||
{
|
||||
if (0 == _currentRow) return false;
|
||||
if (-1 == _currentRow) return false;
|
||||
--_currentRow;
|
||||
return true;
|
||||
}
|
||||
@ -130,7 +130,7 @@ bool RecordSet::moveLast()
|
||||
{
|
||||
if (rowCount() > 0)
|
||||
{
|
||||
_currentRow = rowCount();
|
||||
_currentRow = rowCount() - 1;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
|
@ -258,7 +258,7 @@ void StatementImpl::makeExtractors(Poco::UInt32 count)
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
const MetaColumn& mc = metaColumn(i+1);
|
||||
const MetaColumn& mc = metaColumn(i);
|
||||
switch (mc.type())
|
||||
{
|
||||
case MetaColumn::FDT_BOOL:
|
||||
@ -310,7 +310,7 @@ const MetaColumn& StatementImpl::metaColumn(const std::string& name) const
|
||||
Poco::UInt32 cols = columnsReturned();
|
||||
for (Poco::UInt32 i = 0; i < cols; ++i)
|
||||
{
|
||||
const MetaColumn& column = metaColumn(i+1);
|
||||
const MetaColumn& column = metaColumn(i);
|
||||
if (0 == icompare(column.name(), name)) return column;
|
||||
}
|
||||
|
||||
|
@ -346,10 +346,10 @@ void DataTest::readFromBLOB(BinaryReader& reader)
|
||||
|
||||
void DataTest::testColumn()
|
||||
{
|
||||
MetaColumn mc(1, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true);
|
||||
MetaColumn mc(0, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true);
|
||||
|
||||
assert (mc.name() == "mc");
|
||||
assert (mc.position() == 1);
|
||||
assert (mc.position() == 0);
|
||||
assert (mc.length() == 2);
|
||||
assert (mc.precision() == 3);
|
||||
assert (mc.type() == MetaColumn::FDT_DOUBLE);
|
||||
@ -365,13 +365,13 @@ void DataTest::testColumn()
|
||||
Column<int> c(mc, pData);
|
||||
|
||||
assert (c.rowCount() == 5);
|
||||
assert (c[1] == 1);
|
||||
assert (c[2] == 2);
|
||||
assert (c[3] == 3);
|
||||
assert (c[4] == 4);
|
||||
assert (c[5] == 5);
|
||||
assert (c[0] == 1);
|
||||
assert (c[1] == 2);
|
||||
assert (c[2] == 3);
|
||||
assert (c[3] == 4);
|
||||
assert (c[4] == 5);
|
||||
assert (c.name() == "mc");
|
||||
assert (c.position() == 1);
|
||||
assert (c.position() == 0);
|
||||
assert (c.length() == 2);
|
||||
assert (c.precision() == 3);
|
||||
assert (c.type() == MetaColumn::FDT_DOUBLE);
|
||||
@ -386,20 +386,20 @@ void DataTest::testColumn()
|
||||
Column<int> c1 = c;
|
||||
|
||||
assert (c1.rowCount() == 5);
|
||||
assert (c1[1] == 1);
|
||||
assert (c1[2] == 2);
|
||||
assert (c1[3] == 3);
|
||||
assert (c1[4] == 4);
|
||||
assert (c1[5] == 5);
|
||||
assert (c1[0] == 1);
|
||||
assert (c1[1] == 2);
|
||||
assert (c1[2] == 3);
|
||||
assert (c1[3] == 4);
|
||||
assert (c1[4] == 5);
|
||||
|
||||
Column<int> c2(c1);
|
||||
|
||||
assert (c2.rowCount() == 5);
|
||||
assert (c2[1] == 1);
|
||||
assert (c2[2] == 2);
|
||||
assert (c2[3] == 3);
|
||||
assert (c2[4] == 4);
|
||||
assert (c2[5] == 5);
|
||||
assert (c2[0] == 1);
|
||||
assert (c2[1] == 2);
|
||||
assert (c2[2] == 3);
|
||||
assert (c2[3] == 4);
|
||||
assert (c2[4] == 5);
|
||||
|
||||
std::vector<int> vi;
|
||||
vi.assign(c.begin(), c.end());
|
||||
|
Loading…
Reference in New Issue
Block a user