[odb-users] PRAGMA_DB in preprocessor define

Zhao Xiang xiang.zhao at gamegou.com
Tue Nov 3 00:10:48 EST 2015


Dear ODB Support,


I'm currently using odb 2.4.0 windows version.


I'm trying to put a "#pragma db column" in a preprocessor macro define so I can reuse it:


#define ODB_COUNT_EXISTS(obj, key) \

	PRAGMA_DB(view object(obj)) \

	struct obj##_count \

	{ \

		PRAGMA_DB(column("count(" + obj::key + ")")) \

		std::size_t count; \

	}; \

	PRAGMA_DB(view object(obj)) \

	struct obj##_exists \

	{ \

		PRAGMA_DB(column("exists(" + obj::key + ")")) \

		bool exists; \

	};




ODB_COUNT_EXISTS(group_fans_record, key.user_id)



However the odb compiler gives me two errors:


1>  OdbSchema.hxx:1187:4: error: db pragma 'column' is not associated with a declaration
1>  OdbSchema.hxx:1187:4: error: db pragma 'column' is not associated with a declaration



I tried to expand the code with "gcc -E", and put the result back to the original code:


# 1201 "OdbSchema.hxx"

#pragma db view object(group_fans_record)

# 1201 "OdbSchema.hxx"

 struct group_fans_record_count {

# 1201 "OdbSchema.hxx"

#pragma db column("count(" + group_fans_record::key.user_id + ")")

# 1201 "OdbSchema.hxx"

 std::size_t count; };

# 1201 "OdbSchema.hxx"

#pragma db view object(group_fans_record)

# 1201 "OdbSchema.hxx"

 struct group_fans_record_exists {

# 1201 "OdbSchema.hxx"

#pragma db column("exists(" + group_fans_record::key.user_id + ")")

# 1201 "OdbSchema.hxx"

 bool exists; };



Well this time odb generates what I need.


Is there something I can do about it?


Thanks


Zhao Xiang


More information about the odb-users mailing list