Datatype "TEXT" in Oracle

Forum for posting problems using QxOrm library

Datatype "TEXT" in Oracle

Postby hayt » Mon Oct 24, 2011 1:59 pm

Hello,

I try to use QxORM with Oracle 10g and when I want to create a table with QxORM it wants to create a textfield with the type "TEXT". In Oracle there is no tyoe "TEXT" but VARCHAR. The AUTOINCREMENT Function is also not working (I disabled this for the moment).

Is there an option to change this or did I something wrong with my OCI plugin?

I get the output:
[QxOrm] execute sql query failed : CREATE TABLE TestElementType (test_element_type_id INTEGER NOT NULL PRIMARY KEY, test_element_type_name TEXT)
and an oracle error 902.

I tried the same with VARCHAR(200) instead of TEXT and it worked.
Any pointers, what to do?

greetz
Ricardo
hayt
 

Re: Datatype "TEXT" in Oracle

Postby hayt » Mon Oct 24, 2011 3:13 pm

OK I Found the solution myself

I just changed the SQL Type manually in register_class like:

Code: Select all
IxDataMember* p =  t.data(&TestElementType::testElementName, "test_element_type_name");
p->setSqlType("VARCHAR(255)");


Dont know if this is the intended way, but it works for me

greetz
Ricardo
hayt
 

Re: Datatype "TEXT" in Oracle

Postby QxOrm admin » Thu Oct 27, 2011 8:05 am

Hi,

Your code is correct if you want to change the SQL type for a specific column mapped to a C++ property.
If you want to change it more globally, you must use the following collection :
Code: Select all
QHash<QString, QString> * lstSqlType = qx::QxClassX::getAllSqlTypeByClassName();

This collection associates all SQL types by class name : http://www.qxorm.com/doxygen/html/class ... ass_x.html

So you can write something like this in your code to associate VARCHAR type to all C++ strings :
Code: Select all
lstSqlType->insert("QString", "VARCHAR(255)");
lstSqlType->insert("std::string", "VARCHAR(255)");
// etc...

This will overwrite the default settings provided by QxOrm library and you don't have to write "p->setSqlType("VARCHAR(255)");" in your register function.

There is a thread in the french forum about it, so if you understand a little bit french, you can read here :
http://www.developpez.net/forums/d11377 ... ype-quuid/

PS : if you read some other threads in this forum, you will see that I don't recommend to use qx::create_table<T>() function (I recommend to design the database with a tool provided by your SGBD).
qx::create_table<T>() must be used only for prototypes or samples.
All other queries (SELECT, INSERT, UPDATE, DELETE) will work correctly with Oracle database...
QxOrm library doesn't create for you your SQL schema : you have to create it => if you want a sample, you can see the method "qx::QxClassX::dumpSqlSchema()" in the file "./src/QxRegister/QxClassX.cpp".
I will create a new Question&Response in the FAQ to explain how it works with another sample to PostgreSQL database.
Moreover, this is a good training to understand introspection engine of QxOrm library ;)

PS2 : a new version (QxOrm 1.2.1) will be released in few days with this new entry to the FAQ : "How to build your own SQL schema (create and update tables) based on C++ persistents classes registered into QxOrm context ?"
QxOrm admin
 

Re: Datatype "TEXT" in Oracle

Postby QxOrm admin » Mon Oct 31, 2011 3:25 pm

QxOrm 1.2.1 just released, and I think there is now 2 questions/answers in the FAQ that can help you :
- http://www.qxorm.com/qxorm_en/faq.html#faq_230
- http://www.qxorm.com/qxorm_en/faq.html#faq_240
QxOrm admin
 


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 3 guests

cron