Skip to content

Commit 108a7f4

Browse files
authored
[BREAKING] Add getDoubleField() and update getFloatField() (#12)
This patch converts `getFloatField()` to return a 32-bit `float` instead of a 64-bit `double` and introduces a new `getDoubleField()` member that can be used to return the value as a 64-bit `double` (what `getFloatField()` used to do).
1 parent ffd4a85 commit 108a7f4

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

CppSQLite3.cpp

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,26 +481,46 @@ long long CppSQLite3Query::getInt64Field(const char* szField, long long nNullVal
481481
}
482482

483483

484-
double CppSQLite3Query::getFloatField(int nField, double fNullValue/*=0.0*/) const
484+
float CppSQLite3Query::getFloatField(int nField, float fNullValue/*=0.0f*/) const
485485
{
486486
if (fieldDataType(nField) == SQLITE_NULL)
487487
{
488488
return fNullValue;
489489
}
490490
else
491491
{
492-
return sqlite3_column_double(mpVM, nField);
492+
return static_cast<float>(sqlite3_column_double(mpVM, nField));
493493
}
494494
}
495495

496496

497-
double CppSQLite3Query::getFloatField(const char* szField, double fNullValue/*=0.0*/) const
497+
float CppSQLite3Query::getFloatField(const char* szField, float fNullValue/*=0.0f*/) const
498498
{
499499
int nField = fieldIndex(szField);
500500
return getFloatField(nField, fNullValue);
501501
}
502502

503503

504+
double CppSQLite3Query::getDoubleField(int nField, double dNullValue/*=0.0*/) const
505+
{
506+
if (fieldDataType(nField) == SQLITE_NULL)
507+
{
508+
return dNullValue;
509+
}
510+
else
511+
{
512+
return sqlite3_column_double(mpVM, nField);
513+
}
514+
}
515+
516+
517+
double CppSQLite3Query::getDoubleField(const char* szField, double dNullValue/*=0.0*/) const
518+
{
519+
int nField = fieldIndex(szField);
520+
return getDoubleField(nField, dNullValue);
521+
}
522+
523+
504524
const char* CppSQLite3Query::getStringField(int nField, const char* szNullValue/*=""*/) const
505525
{
506526
if (fieldDataType(nField) == SQLITE_NULL)
@@ -835,26 +855,52 @@ int CppSQLite3Table::getIntField(const char* szField, int nNullValue/*=0*/) cons
835855
}
836856

837857

838-
double CppSQLite3Table::getFloatField(int nField, double fNullValue/*=0.0*/) const
858+
float CppSQLite3Table::getFloatField(int nField, float fNullValue/*=0.0f*/) const
839859
{
840860
if (fieldIsNull(nField))
841861
{
842862
return fNullValue;
843863
}
844864
else
845865
{
846-
return atof(fieldValue(nField));
866+
return static_cast<float>(atof(fieldValue(nField)));
847867
}
848868
}
849869

850870

851-
double CppSQLite3Table::getFloatField(const char* szField, double fNullValue/*=0.0*/) const
871+
float CppSQLite3Table::getFloatField(const char* szField, float fNullValue/*=0.0f*/) const
852872
{
853873
if (fieldIsNull(szField))
854874
{
855875
return fNullValue;
856876
}
857877
else
878+
{
879+
return static_cast<float>(atof(fieldValue(szField)));
880+
}
881+
}
882+
883+
884+
double CppSQLite3Table::getDoubleField(int nField, double dNullValue/*=0.0*/) const
885+
{
886+
if (fieldIsNull(nField))
887+
{
888+
return dNullValue;
889+
}
890+
else
891+
{
892+
return atof(fieldValue(nField));
893+
}
894+
}
895+
896+
897+
double CppSQLite3Table::getDoubleField(const char* szField, double dNullValue/*=0.0*/) const
898+
{
899+
if (fieldIsNull(szField))
900+
{
901+
return dNullValue;
902+
}
903+
else
858904
{
859905
return atof(fieldValue(szField));
860906
}

CppSQLite3.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,11 @@ class CppSQLite3Query
166166
long long getInt64Field(int nField, long long nNullValue=0) const;
167167
long long getInt64Field(const char* szField, long long nNullValue=0) const;
168168

169-
double getFloatField(int nField, double fNullValue=0.0) const;
170-
double getFloatField(const char* szField, double fNullValue=0.0) const;
169+
float getFloatField(int nField, float fNullValue=0.0f) const;
170+
float getFloatField(const char* szField, float fNullValue=0.0f) const;
171+
172+
double getDoubleField(int nField, double dNullValue=0.0) const;
173+
double getDoubleField(const char* szField, double dNullValue=0.0) const;
171174

172175
const char* getStringField(int nField, const char* szNullValue="") const;
173176
const char* getStringField(const char* szField, const char* szNullValue="") const;
@@ -222,8 +225,11 @@ class CppSQLite3Table
222225
int getIntField(int nField, int nNullValue=0) const;
223226
int getIntField(const char* szField, int nNullValue=0) const;
224227

225-
double getFloatField(int nField, double fNullValue=0.0) const;
226-
double getFloatField(const char* szField, double fNullValue=0.0) const;
228+
float getFloatField(int nField, float fNullValue=0.0f) const;
229+
float getFloatField(const char* szField, float fNullValue=0.0f) const;
230+
231+
double getDoubleField(int nField, double dNullValue=0.0) const;
232+
double getDoubleField(const char* szField, double dNullValue=0.0) const;
227233

228234
const char* getStringField(int nField, const char* szNullValue="") const;
229235
const char* getStringField(const char* szField, const char* szNullValue="") const;

0 commit comments

Comments
 (0)