Nebula
Loading...
Searching...
No Matches
command.h
Go to the documentation of this file.
1#pragma once
2#ifndef DB_COMMAND_H
3#define DB_COMMAND_H
4//------------------------------------------------------------------------------
15#include "core/refcounted.h"
16#include "attr/attrid.h"
17#include "util/string.h"
18#include "db/valuetable.h"
19
20//------------------------------------------------------------------------------
21namespace Db
22{
23class Database;
24
26{
27public:
29 Command();
31 virtual ~Command();
32
34 virtual bool Compile(const Ptr<Database>& db, const Util::String& sqlCommand, ValueTable* resultTable=0);
36 virtual bool Execute() = 0;
38 bool CompileAndExecute(const Ptr<Database>& db, const Util::String& sqlCommand, ValueTable* resultTable=0);
40 virtual void Clear() = 0;
42 virtual bool IsValid() const = 0;
44 const Util::String& GetError() const;
45
47 const Ptr<Database>& GetDatabase() const;
49 const Util::String& GetSqlCommand() const;
51 const Ptr<ValueTable>& GetValueTable() const;
52
54 virtual IndexT IndexOf(const Util::String& name) const = 0;
56 virtual IndexT IndexOf(const Attr::AttrId& attrId) const = 0;
57
59 virtual void BindInt(IndexT index, int val) = 0;
61 virtual void BindUInt(IndexT index, unsigned int val) = 0;
63 virtual void BindInt64(IndexT index, int64_t val) = 0;
65 virtual void BindFloat(IndexT index, float val) = 0;
67 virtual void BindBool(IndexT index, bool val) = 0;
69 virtual void BindVec4(IndexT index, const Math::vec4& val) = 0;
71 virtual void BindString(IndexT index, const Util::String& val) = 0;
73 virtual void BindMat4(IndexT index, const Math::mat4& val) = 0;
75 virtual void BindBlob(IndexT index, const Util::Blob& val) = 0;
77 virtual void BindGuid(IndexT index, const Util::Guid& val) = 0;
78
80 virtual void BindInt(const Util::String& name, int val) = 0;
82 virtual void BindInt64(const Util::String& name, int64_t val) = 0;
84 virtual void BindUInt(const Util::String& name, unsigned int val) = 0;
86 virtual void BindFloat(const Util::String& name, float val) = 0;
88 virtual void BindBool(const Util::String& name, bool val) = 0;
90 virtual void BindVec4(const Util::String& name, const Math::vec4& val) = 0;
92 virtual void BindString(const Util::String& name, const Util::String& val) = 0;
94 virtual void BindMat4(const Util::String& name, const Math::mat4& val) = 0;
96 virtual void BindBlob(const Util::String& name, const Util::Blob& val) = 0;
98 virtual void BindGuid(const Util::String& name, const Util::Guid& val) = 0;
99
101 virtual void BindInt(const Attr::AttrId& id, int val) = 0;
103 virtual void BindInt64(const Attr::AttrId& id, int64_t val) = 0;
105 virtual void BindUInt(const Attr::AttrId& id, unsigned int val) = 0;
107 virtual void BindFloat(const Attr::AttrId& id, float val) = 0;
109 virtual void BindBool(const Attr::AttrId& id, bool val) = 0;
111 virtual void BindVec4(const Attr::AttrId& id, const Math::vec4& val) = 0;
113 virtual void BindString(const Attr::AttrId& id, const Util::String& val) = 0;
115 virtual void BindMat4(const Attr::AttrId& id, const Math::mat4& val) = 0;
117 virtual void BindBlob(const Attr::AttrId& id, const Util::Blob& val) = 0;
119 virtual void BindGuid(const Attr::AttrId& id, const Util::Guid& val) = 0;
120
121protected:
123 void SetError(const Util::String& err);
125 void SetSqlCommand(const Util::String& cmd);
126
131};
132
133//------------------------------------------------------------------------------
136inline const Ptr<ValueTable>&
138{
139 return this->valueTable;
140}
141
142//------------------------------------------------------------------------------
145inline const Ptr<Database>&
147{
148 return this->database;
149}
150
151//------------------------------------------------------------------------------
154inline void
156{
157 n_assert(cmd.IsValid());
158 this->sqlCommand = cmd;
159}
160
161//------------------------------------------------------------------------------
164inline const Util::String&
166{
167 return this->sqlCommand;
168}
169
170//------------------------------------------------------------------------------
173inline void
175{
176 this->error = err;
177}
178
179//------------------------------------------------------------------------------
182inline const Util::String&
184{
185 return this->error;
186}
187
188} // namespace Db
189//------------------------------------------------------------------------------
190#endif
An attribute ID is used to carry attribute types (no values) around.
Definition attrid.h:20
The common base class of Nebula.
Definition refcounted.h:38
virtual IndexT IndexOf(const Attr::AttrId &attrId) const =0
convert a parameter attribute id into an integer index
virtual void BindInt64(IndexT index, int64_t val)=0
bind a 64 bit integer by placeholder to 0-based index
virtual bool Execute()=0
execute compiled command
virtual void BindBlob(IndexT index, const Util::Blob &val)=0
bind a blob by placeholder index 0-based index
virtual void BindString(const Util::String &name, const Util::String &val)=0
bind a string by placeholder name
virtual void BindBool(IndexT index, bool val)=0
bind a bool by placeholder index 0-based index
virtual void BindMat4(IndexT index, const Math::mat4 &val)=0
bind a mat4 by placeholder index 0-based index
virtual void BindUInt(IndexT index, unsigned int val)=0
bind an unsigned integer by placeholder to 0-based index
const Ptr< Database > & GetDatabase() const
get back pointer to database
Definition command.h:146
virtual void BindInt(const Util::String &name, int val)=0
bind an integer by placeholder name
virtual void BindUInt(const Util::String &name, unsigned int val)=0
bind an unsigned integer by placeholder name
void SetError(const Util::String &err)
set error string
Definition command.h:174
virtual void BindInt64(const Util::String &name, int64_t val)=0
bind an 64 bit integer by placeholder name
virtual bool IsValid() const =0
return true if command is compiled and ready for execution
const Util::String & GetSqlCommand() const
get the last compiled SQL command
Definition command.h:165
const Util::String & GetError() const
get last error
Definition command.h:183
void SetSqlCommand(const Util::String &cmd)
set the SQL statement to exeute
Definition command.h:155
Util::String sqlCommand
Definition command.h:127
virtual void Clear()=0
clear the current command
bool CompileAndExecute(const Ptr< Database > &db, const Util::String &sqlCommand, ValueTable *resultTable=0)
shortcut for simple SQL commands
Definition command.cc:54
Util::String error
Definition command.h:128
virtual void BindGuid(const Util::String &name, const Util::Guid &val)=0
bind a guid by placeholder name
virtual void BindMat4(const Attr::AttrId &id, const Math::mat4 &val)=0
bind a mat4 by placeholder attribute id
virtual void BindString(IndexT index, const Util::String &val)=0
bind a string by placeholder index 0-based index
virtual void BindFloat(IndexT index, float val)=0
bind a float by placeholder index to 0-based index
Ptr< ValueTable > valueTable
Definition command.h:130
virtual void BindInt(IndexT index, int val)=0
bind an integer by placeholder to 0-based index
virtual void BindInt(const Attr::AttrId &id, int val)=0
bind an integer by placeholder attribute id
virtual void BindBool(const Attr::AttrId &id, bool val)=0
bind a bool by placeholder attribute id
virtual void BindString(const Attr::AttrId &id, const Util::String &val)=0
bind a string by placeholder attribute id
virtual void BindVec4(IndexT index, const Math::vec4 &val)=0
bind a vec4 by placeholder index 0-based index
virtual IndexT IndexOf(const Util::String &name) const =0
convert a parameter name into an integer index
virtual void BindBlob(const Attr::AttrId &id, const Util::Blob &val)=0
bind a blob by placeholder attribute id
const Ptr< ValueTable > & GetValueTable() const
get the last set value table (can be 0!)
Definition command.h:137
virtual void BindInt64(const Attr::AttrId &id, int64_t val)=0
bind an 64 bit integer by placeholder attribute id
virtual void BindBool(const Util::String &name, bool val)=0
bind a bool by placeholder name
Ptr< Database > database
Definition command.h:129
virtual void BindMat4(const Util::String &name, const Math::mat4 &val)=0
bind a mat4 by placeholder name
virtual void BindVec4(const Attr::AttrId &id, const Math::vec4 &val)=0
bind a vec4 by placeholder attribute id
virtual void BindFloat(const Attr::AttrId &id, float val)=0
bind a float by placeholder attribute id
virtual void BindBlob(const Util::String &name, const Util::Blob &val)=0
bind a blob by placeholder name
virtual void BindVec4(const Util::String &name, const Math::vec4 &val)=0
bind a vec4 by placeholder name
virtual void BindGuid(const Attr::AttrId &id, const Util::Guid &val)=0
bind a guid by placeholder attribute id
virtual ~Command()
destructor
Definition command.cc:24
virtual void BindGuid(IndexT index, const Util::Guid &val)=0
bind a guid by placeholder index 0-based index
Command()
constructor
Definition command.cc:16
virtual void BindUInt(const Attr::AttrId &id, unsigned int val)=0
bind an unsigned integer by placeholder attribute id
virtual bool Compile(const Ptr< Database > &db, const Util::String &sqlCommand, ValueTable *resultTable=0)
compile an SQL statement with optional placeholders
Definition command.cc:37
virtual void BindFloat(const Util::String &name, float val)=0
bind a float by placeholder name
A table of database values.
Definition valuetable.h:23
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
#define n_assert(exp)
Definition debug.h:50
Definition column.cc:10
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition String.cs:8
bool IsValid() const
return true if string object is not empty
Definition string.h:700
int IndexT
Definition types.h:41