[odb-users] Native SQL Query
    Mike Ruffing 
    mike.ruffing at ipconfigure.com
       
    Tue Nov 19 14:49:08 EST 2013
    
    
  
Boris,
Thanks for the quick response.
Here is the exact query instantiation with the object type:
odb::query<server> q ("first = 'John' AND age = " + odb::query<server>::_ref (age));
I have also included the server object declaration.
#pragma db object
//! @brief Persistent class for an ESM server.
class server : public std::enable_shared_from_this<server>
{
	public:
		server(const std::string& name, const boost::uuids::uuid& uuid) : name_(name), uuid_(uuid) {}
		~server() {}
		//////////////////////////////////////////////////////////////////////////////
		// Setters & getters:
		//////////////////////////////////////////////////////////////////////////////
		const std::string& name() const { return name_; }
		void name(const std::string& name) { name_ = name; }
		const boost::uuids::uuid& uuid() const { return uuid_; }
		
		const std::vector< ::odb::lazy_weak_ptr<camera> >& cameras() const { return cameras_; }
		const std::vector< ::odb::lazy_weak_ptr<storage_location> >& storage_locations() const { return storage_locations_; }
		const unsigned long id() const { return server_id_; }
		//////////////////////////////////////////////////////////////////////////////
		// Bidirectional adders:
		//////////////////////////////////////////////////////////////////////////////
		void add_storage_location(std::shared_ptr<ipc::esm::storage_location>& new_storage_location);
		void add_camera(std::shared_ptr<ipc::esm::camera>& new_camera);
	private:
		friend class ::odb::access;
		server() {}
		server(const server& b_server) {};
		//////////////////////////////////////////////////////////////////////////////
		// Data members:
		//////////////////////////////////////////////////////////////////////////////
		//! @brief Server ID, auto-assigned.
		#pragma db id auto
		unsigned long server_id_;	
		//! @brief Server name, i.e. "Cort's ESM server".
		#pragma db not_null
		std::string name_;			
		//!< @brief Server UUID, retained by a server identify itself in a shared database.
		#pragma db not_null
		boost::uuids::uuid uuid_;						
		//!< @brief List of active and inactive storage locations on this server.
		#pragma db value_not_null inverse(server_)
		std::vector< ::odb::lazy_weak_ptr<storage_location> > storage_locations_;
		//!< @brief List of active and inactive cameras on this server.
		#pragma db value_not_null inverse(server_)
		std::vector< ::odb::lazy_weak_ptr<camera> > cameras_;
};
-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Tuesday, November 19, 2013 2:35 PM
To: Mike Ruffing
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Native SQL Query
Hi Mike,
Mike Ruffing <mike.ruffing at ipconfigure.com> writes:
> query q ("first = 'John' AND age = " + query::_ref (age));
> 
> error C2678: binary '+' : no operator found which takes a left-hand 
> operand of type 'const char [26]'
We have pretty much the same line in one of the tests and it compiles fine. What is the 'query' type? You should have something like this before the above line:
typedef odb::query<my_object> query;
Boris
    
    
More information about the odb-users
mailing list