Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base class not create sql params #118

Open
hs205118 opened this issue Jan 10, 2024 · 3 comments
Open

base class not create sql params #118

hs205118 opened this issue Jan 10, 2024 · 3 comments

Comments

@hs205118
Copy link

hs205118 commented Jan 10, 2024

Hi,
I create a class Entity被检设备接口管理::EntityBase, and then I insert one record, but the base class EntityBase.id always no data.
And the sql shows:

INSERT INTO t_eqpt_device_interface (interface_type, eqpt_equipment_info_id, ip, port, serial_port_number, band_rate, parity, data, stop, parallel_port_device_address, usb_device_address, create_time) VALUES (:interface_type, :eqpt_equipment_info_id, :ip, :port, :serial_port_number, :band_rate, :parity, :data, :stop, :parallel_port_device_address, :usb_device_address, :create_time)

No EntityBase.id
Why there is no id?

EntityBase.h

#define BigInt int64_t

class EntityBase
{
public:
	int64_t id = 0;
	EntityBase()
	{
	}
}
QX_REGISTER_PRIMARY_KEY(EntityBase, int64_t)
QX_REGISTER_HPP_EXPORT_DLL(EntityBase, qx::trait::no_base_class_defined, DB_VERSION)

EntityBase.cpp

QX_REGISTER_CPP_EXPORT_DLL(EntityBase)

namespace qx
{
	template <> void register_class(QxClass<EntityBase>& t)
	{
		t.id(&EntityBase::id, "id", DB_VERSION);
	}
}
class Entity被检设备接口管理 :
	public EntityBase
{
public:
	/// <summary>
	/// A.interface_type
	/// </summary>
	int                 接口类型       = 0;
	/// <summary>
	/// A.eqpt_equipment_info_id
	/// </summary>
	BigInt              被检设备Id     = 0;
	/// <summary>
	/// A.ip
	/// </summary>
	QString             IP         = "";
	/// <summary>
	/// A.port
	/// </summary>
	int                 端口         = 0;
	/// <summary>
	/// A.serial_port_number
	/// </summary>
	QString             串口号        = "";
	/// <summary>
	/// A.band_rate
	/// </summary>
	QString             波特率        = "";
	/// <summary>
	/// A.parity
	/// </summary>
	QString             校验位        = "";
	/// <summary>
	/// A.data
	/// </summary>
	QString             数据位        = "";
	/// <summary>
	/// A.stop
	/// </summary>
	QString             停止位        = "";
	/// <summary>
	/// A.parallel_port_device_address
	/// </summary>
	QString             并口地址       = "";
	/// <summary>
	/// A.usb_device_address
	/// </summary>
	QString             USB地址      = "";
	/// <summary>
	/// A.create_time
	/// </summary>
	QDateTime           创建时间       = QDateTime::currentDateTime();


	Entity被检设备接口管理()
	{
	}
};

QX_REGISTER_HPP_EXPORT_DLL(Entity被检设备接口管理, EntityBase, DB_VERSION)
QX_REGISTER_CPP_EXPORT_DLL(Entity被检设备接口管理)

namespace qx
{
	template <> void register_class(QxClass<Entity被检设备接口管理>& t)
	{
		t.setName("t_eqpt_device_interface");
		t.data(&Entity被检设备接口管理::接口类型, "interface_type");
		t.data(&Entity被检设备接口管理::被检设备Id, "eqpt_equipment_info_id");
		t.data(&Entity被检设备接口管理::IP, "ip");
		t.data(&Entity被检设备接口管理::端口, "port");
		t.data(&Entity被检设备接口管理::串口号, "serial_port_number");
		t.data(&Entity被检设备接口管理::波特率, "band_rate");
		t.data(&Entity被检设备接口管理::校验位, "parity");
		t.data(&Entity被检设备接口管理::数据位, "data");
		t.data(&Entity被检设备接口管理::停止位, "stop");
		t.data(&Entity被检设备接口管理::并口地址, "parallel_port_device_address");
		t.data(&Entity被检设备接口管理::USB地址, "usb_device_address");
		t.data(&Entity被检设备接口管理::创建时间, "create_time");

	}
}

@QxOrm
Copy link
Owner

QxOrm commented Jan 10, 2024

Hello,

In your EntityBase class header, I don't see something like this :
QX_REGISTER_HPP_EXPORT_DLL(EntityBase, qx::trait::no_base_class_defined, 0)

@hs205118
Copy link
Author

hs205118 commented Jan 12, 2024

QX_REGISTER_PRIMARY_KEY(EntityBase, BigInt)
QX_REGISTER_HPP_EXPORT_DLL(EntityBase, qx::trait::no_base_class_defined, DB_VERSION)

Yes, I have defined.

Will show:
NOT NULL constraint failed: t_eqpt_device_interface.id
Unable to fetch row

image
image
image
image
image
image

@QxOrm
Copy link
Owner

QxOrm commented Jan 12, 2024

What I would recommend is :
download QxEntityEditor, then with this application, create a base entity, then another entity which inherits from this base entity. Then checks how QxEntityEditor generates the C++ classes.
This way, you will see what is missing or wrong with your class.
You can use QxEntityEditor free of charge with a small project, so no problem to test these kind of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants