summaryrefslogtreecommitdiff
path: root/ADBC/adbc/SQLite/Parameter.cpp
blob: 049708b0dc9173b6cd3947ad265c35a64c18a967 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// $Id$

#include "Parameter.h"

#if !defined (__ADBC_INLINE__)
#include "Parameter.inl"
#endif

#include "Exception.h"
#include "Query.h"
#include "Types.h"
#include "sqlite3.h"

namespace ADBC
{
namespace SQLite
{
//
// operator =
//
const Parameter & Parameter::operator = (const Parameter & rhs)
{
  if (this == &rhs)
    return *this;

  this->owner_ = rhs.owner_;
  this->index_ = rhs.index_;

  return *this;
}

//
// null
//
void Parameter::null (void)
{
  int retval = ::sqlite3_bind_null (this->owner_->owner ().stmt_,
                                    this->index_);

  if (retval != SQLITE_OK)
    throw Exception (this->owner_->owner ().parent_);

  this->is_null_ = true;
}

//
// bind
//
void Parameter::bind (const char * buffer, size_t bufsize)
{
  int retval = ::sqlite3_bind_text (this->owner_->owner ().stmt_,
                                    this->index_,
                                    buffer,
                                    bufsize,
                                    SQLITE_TRANSIENT);

  if (retval == SQLITE_OK)
    ::ADBC::Parameter::bind (buffer, bufsize);
  else
    throw Exception (this->owner_->owner ().parent_);
}

//
// bind
//
void Parameter::bind (char * buffer, size_t bufsize)
{
  int retval = ::sqlite3_bind_text (this->owner_->owner ().stmt_,
                                    this->index_,
                                    buffer,
                                    bufsize,
                                    SQLITE_TRANSIENT);

  if (retval == SQLITE_OK)
    ::ADBC::Parameter::bind (buffer, bufsize);
  else
    throw Exception (this->owner_->owner ().parent_);
}

//
// bind
//
void Parameter::bind (::ADBC::Date_Time * date_time)
{
  // Cast the object its concrete type.
  ADBC::SQLite::Date_Time * dt =
    dynamic_cast <::ADBC::SQLite::Date_Time *> (date_time);

  if (0 != dt)
    this->bind (dt);

  // Throw an exception since type is invalid.
  throw Exception ("value is not an ::ADBC::SQLite::Date_Time object");
}

//
// bind
//
void Parameter::bind (::ADBC::SQLite::Date_Time * dt)
{
  char * value = reinterpret_cast <char *> (dt->value ());
  this->bind (value, 20);

  ::ADBC::Parameter::bind (dt);
}

//
// bind_int
//
void Parameter::bind_int (int val)
{
  int retval = ::sqlite3_bind_int (this->owner_->owner ().stmt_,
                                   this->index_,
                                   val);

  if (retval != SQLITE_OK)
    throw Exception (this->owner_->owner ().parent_);
}

//
// bind_double
//
void Parameter::bind_double (double val)
{
  int retval =
    ::sqlite3_bind_double (this->owner_->owner ().stmt_,
                           this->index_,
                           val);

  if (retval != SQLITE_OK)
    throw Exception (this->owner_->owner ().parent_);
}

}
}