00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/data/CommandParameter.h>
00018 #include <spl/data/ColumnTypes.h>
00019
00020 CommandParameter::CommandParameter(const String& name, int type, int dir, int len)
00021 : m_name(name), m_type(type), m_dir(dir), m_data(), m_len(len)
00022 {
00023 switch( type )
00024 {
00025 case DbSqlType::SQL_TYPE_INT8:
00026 m_len = 1;
00027 m_isnumeric = true;
00028 break;
00029 case DbSqlType::SQL_TYPE_INT16:
00030 m_len = 2;
00031 m_isnumeric = true;
00032 break;
00033 case DbSqlType::SQL_TYPE_INT32:
00034 m_len = 4;
00035 m_isnumeric = true;
00036 break;
00037 case DbSqlType::SQL_TYPE_INT64:
00038 m_len = 8;
00039 m_isnumeric = true;
00040 break;
00041 case DbSqlType::SQL_TYPE_DECIMAL:
00042 m_isnumeric = true;
00043 break;
00044 case DbSqlType::SQL_TYPE_FLOAT32:
00045 m_len = 4;
00046 m_isnumeric = true;
00047 break;
00048 case DbSqlType::SQL_TYPE_FLOAT64:
00049 m_len = 8;
00050 m_isnumeric = true;
00051 break;
00052 case DbSqlType::SQL_TYPE_FLAG:
00053 m_isnumeric = true;
00054 break;
00055 case DbSqlType::SQL_TYPE_TIMESTAMP:
00056 m_len = 8;
00057 m_isnumeric = false;
00058 break;
00059 case DbSqlType::SQL_TYPE_DATE:
00060 m_isnumeric = false;
00061 break;
00062 case DbSqlType::SQL_TYPE_DATETIME:
00063 m_len = 8;
00064 m_isnumeric = false;
00065 break;
00066 case DbSqlType::SQL_TYPE_CHAR:
00067 m_isnumeric = false;
00068 break;
00069 case DbSqlType::SQL_TYPE_VARCHAR:
00070 m_isnumeric = false;
00071 break;
00072 case DbSqlType::SQL_TYPE_BLOB:
00073 m_isnumeric = false;
00074 break;
00075 }
00076 }
00077
00078 CommandParameter::CommandParameter(const String& name, int8 val)
00079 : m_name(name), m_type(DbSqlType::SQL_TYPE_INT8), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(1)
00080 {
00081 }
00082
00083 CommandParameter::CommandParameter(const String& name, int16 val)
00084 : m_name(name), m_type(DbSqlType::SQL_TYPE_INT16), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(2)
00085 {
00086 }
00087
00088 CommandParameter::CommandParameter(const String& name, int32 val)
00089 : m_name(name), m_type(DbSqlType::SQL_TYPE_INT32), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(4)
00090 {
00091 }
00092
00093 CommandParameter::CommandParameter(const String& name, int64 val)
00094 : m_name(name), m_type(DbSqlType::SQL_TYPE_INT64), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(8)
00095 {
00096 }
00097
00098 CommandParameter::CommandParameter(const String& name, float32 val)
00099 : m_name(name), m_type(DbSqlType::SQL_TYPE_FLOAT32), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(4)
00100 {
00101 }
00102
00103 CommandParameter::CommandParameter(const String& name, float64 val)
00104 : m_name(name), m_type(DbSqlType::SQL_TYPE_FLOAT64), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(8)
00105 {
00106 }
00107
00108 CommandParameter::CommandParameter(const String& name, bool val)
00109 : m_name(name), m_type(DbSqlType::SQL_TYPE_FLAG), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(4)
00110 {
00111 }
00112
00113 CommandParameter::CommandParameter(const String& name, DateTime val)
00114 : m_name(name), m_type(DbSqlType::SQL_TYPE_DATETIME), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val), m_len(8)
00115 {
00116 }
00117
00118 CommandParameter::CommandParameter(const String& name, char *val)
00119 : m_name(name), m_type(DbSqlType::SQL_TYPE_VARCHAR), m_dir(ParameterDirection::PARAM_DIR_IN), m_data(val)
00120 {
00121 m_len = (int)strlen(val);
00122 }
00123
00124 CommandParameter::CommandParameter(const CommandParameter& prm)
00125 : m_name(prm.m_name),
00126 m_type(prm.m_type),
00127 m_dir(prm.m_dir),
00128 m_data(prm.m_data),
00129 m_isnumeric(prm.m_isnumeric),
00130 m_len(prm.m_len)
00131 {
00132 }
00133
00134 CommandParameter::~CommandParameter()
00135 {
00136 }
00137
00138 CommandParameter& CommandParameter::operator =(const CommandParameter& prm)
00139 {
00140 m_name = prm.m_name;
00141 m_type = prm.m_type;
00142 m_dir = prm.m_dir;
00143 m_data = prm.m_data;
00144 m_isnumeric = prm.m_isnumeric;
00145 m_len = prm.m_len;
00146
00147 return *this;
00148 }
00149
00150 byte CommandParameter::GetByte()
00151 {
00152 return m_data.ToByte();
00153 }
00154
00155 int16 CommandParameter::GetInt16()
00156 {
00157 return m_data.ToInt16();
00158 }
00159
00160 int32 CommandParameter::GetInt32()
00161 {
00162 return m_data.ToInt32();
00163 }
00164
00165 int64 CommandParameter::GetInt64()
00166 {
00167 return m_data.ToInt64();
00168 }
00169
00170 Decimal CommandParameter::GetDecimal()
00171 {
00172 return m_data.ToDecimal();
00173 }
00174
00175 float32 CommandParameter::GetFloat32()
00176 {
00177 return m_data.ToFloat32();
00178 }
00179
00180 float64 CommandParameter::GetFloat64()
00181 {
00182 return m_data.ToFloat64();
00183 }
00184
00185 bool CommandParameter::GetBit()
00186 {
00187 return m_data.ToBool();
00188 }
00189
00190 DateTime CommandParameter::GetTimeStamp()
00191 {
00192 return m_data.ToDateTime();
00193 }
00194
00195 Date CommandParameter::GetDate()
00196 {
00197 return m_data.ToDate();
00198 }
00199
00200 DateTime CommandParameter::GetDateTime()
00201 {
00202 return m_data.ToDateTime();
00203 }
00204
00205 StringPtr CommandParameter::GetChar()
00206 {
00207 return m_data.ToString();
00208 }
00209
00210 StringPtr CommandParameter::GetVarchar()
00211 {
00212 return m_data.ToString();
00213 }
00214
00215 Variant& CommandParameter::GetVariant()
00216 {
00217 return m_data;
00218 }
00219
00220 void CommandParameter::Set(int8 val)
00221 {
00222 m_data = Variant(val);
00223 }
00224
00225 void CommandParameter::Set(int16 val)
00226 {
00227 m_data = Variant(val);
00228 }
00229
00230 void CommandParameter::Set(int32 val)
00231 {
00232 m_data.ValidateMem();
00233 m_data = Variant(val);
00234 m_data.ValidateMem();
00235 }
00236
00237 void CommandParameter::Set(int64 val)
00238 {
00239 m_data = Variant(val);
00240 }
00241
00242 void CommandParameter::Set(Decimal val)
00243 {
00244 m_data = Variant(val);
00245 }
00246
00247 void CommandParameter::Set(float32 val)
00248 {
00249 m_data = Variant(val);
00250 }
00251
00252 void CommandParameter::Set(float64 val)
00253 {
00254 m_data = Variant(val);
00255 }
00256
00257 void CommandParameter::Set(bool val)
00258 {
00259 m_data = Variant(val);
00260 }
00261
00262 void CommandParameter::Set(DateTime& val)
00263 {
00264 m_data = Variant(val);
00265 }
00266
00267 void CommandParameter::Set(Date& val)
00268 {
00269 m_data = Variant(val);
00270 }
00271
00272 void CommandParameter::Set(const String& val)
00273 {
00274 m_data = Variant(val);
00275 }
00276
00277 #if defined(DEBUG)
00278 void CommandParameter::CheckMem() const
00279 {
00280 m_name.CheckMem();
00281 m_data.CheckMem();
00282 }
00283
00284 void CommandParameter::ValidateMem() const
00285 {
00286 m_name.ValidateMem();
00287 m_data.ValidateMem();
00288 }
00289 #endif
00290