Autoincrement some filed

Forum for posting problems using QxOrm library

Autoincrement some filed

Postby mtfk » Fri May 20, 2011 4:13 pm

HI,

How to increment any other field then id in table?

for example:

t.id(& author::m_id, "author_id"); <- this is autoincrement by default

t.data(& author::position, "name");

and how to make that position filed will be also autoincrement?

Thanks a lot fo any advice
mtfk
 

Re: Autoincrement some filed

Postby QxOrm admin » Sun May 22, 2011 9:08 am

Hi,

This is not a feature of QxOrm library but a feature of your SGBD.
Here is a link found with Google : http://stackoverflow.com/questions/8137 ... ent-column

So yes it's possible but you have to search how to do this with your database ;)
QxOrm admin
 

Re: Autoincrement some filed

Postby mtfk » Mon May 23, 2011 4:30 pm

Thanks for replay,

I know that I can set up it in my database but the question is how to do this using QxOrm.
Whole database is created by QxOrm during start the program. So I want to also create those field with autoincrement.
There is some functionality in QxOrm to do such things?
mtfk
 

Re: Autoincrement some filed

Postby QxOrm admin » Mon May 23, 2011 8:14 pm

I don't recommend to use "qx::create_table<>" in a real project.
I think it is a lot better to design your database with a tool provided by your SGDB.

However, if you really want to use "qx::create_table<>" to create your database by program, you can try this (but I have not tested yet) :
In your "qx::register_class<T>", when you map your class properties, try something like this :

Code: Select all
qx::IxDataMember * pData = NULL;
pData = t.data(& MyClass::m_property, "XXX");
pData->setAutoIncrement(true);


When you use "t.data(...)", an object of type "qx::IxDataMember *" is returned.
Then, you have some methods that you can apply to each property registered into QxOrm context.
When you write "pData->setAutoIncrement(true);", normally, this will add "AUTOINCREMENT" keyword with "qx::create_table<>".
QxOrm admin
 

Re: Autoincrement some filed

Postby luisvaldes88 » Thu Aug 11, 2011 11:25 pm

hello people!

i was thinking about creating a thread about autoincrement fields until i saw this post.

because i hava a specific function to get the correct value for my PK, and QxOrm was giving me an error when inserting, i found the anwser very fast


qx::IxDataMember * pData = NULL;
pData = t.id(& ClassEX::npk_value, "npk_value");
pData->setAutoIncrement(false);


this way it executes the statement

INSERT INTO CLASSEX(NPK_VALUE) VALUES (:NPK_VALUE)


best regards :D
luisvaldes88
 

Re: Autoincrement some filed

Postby QxOrm admin » Fri Aug 12, 2011 10:00 am

Hi,

Thanks for sharing yours tricks about QxOrm library ;)

You are right : by default, a primary key registered into QxOrm library is a long type with autoincrement keyword.
If you want to register another type than long (for example, you want a QString type for your primary key), goto to the FAQ : http://www.qxorm.com/qxorm_en/faq.html#faq_100
And if you don't want autoincrement keyword, use : pData->setAutoIncrement(false);
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 5 guests