Difference between revisions of "Database Tips"

From Opentaps Wiki
Jump to navigationJump to search
(DB2 Tips)
Line 34: Line 34:
 
If you get an error message from DB2, you will get a SQLCODE like below:
 
If you get an error message from DB2, you will get a SQLCODE like below:
 
<pre>
 
<pre>
org.ofbiz.entity.GenericDataSourceException: SQL Exception while executing the following:SELECT SR.SURVEY_RESPONSE_ID, SR.SURVEY_ID, SR.PARTY_ID, SR.RESPONSE_DATE, SR.LAST_MODIFIED_DATE, SR.REFERENCE_ID, SR.GENERAL_FEEDBACK, SR.ORDER_ID, SR.ORDER_ITEM_SEQ_ID, SR.STATUS_ID, SRA.SURVEY_QUESTION_ID, SRA.SURVEY_MULTI_RESP_COL_ID, SRA.SURVEY_MULTI_RESP_ID, SRA.BOOLEAN_RESPONSE, SRA.CURRENCY_RESPONSE, SRA.FLOAT_RESPONSE, SRA.NUMERIC_RESPONSE, SRA.TEXT_RESPONSE, SRA.SURVEY_OPTION_SEQ_ID, SRA.CONTENT_ID, SRA.ANSWERED_DATE, SRA.AMOUNT_BASE, SRA.AMOUNT_BASE_UOM_ID, SRA.WEIGHT_FACTOR, SRA.DURATION, SRA.DURATION_UOM_ID, SRA.SEQUENCE_NUM FROM OPENTAPS.SURVEY_RESPONSE SR INNER JOIN OPENTAPS.SURVEY_RESPONSE_ANSWER SRA ON SR.SURVEY_RESPONSE_ID = SRA.SURVEY_RESPONSE_ID WHERE (SRA.SURVEY_QUESTION_ID = ? AND SR.SURVEY_ID = ?) (DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=63, DRIVER=3.50.152)
+
DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=63, DRIVER=3.50.152
 
</pre>
 
</pre>
  
Line 44: Line 44:
 
Some of the more popular codes are:
 
Some of the more popular codes are:
 
* SQL-204: <name> not recognized.  Most likely, you are referencing a table that doesn't exist.
 
* SQL-204: <name> not recognized.  Most likely, you are referencing a table that doesn't exist.
 +
* SQL-270: Function not supported.  See the SQLERRMC for the message code.
 
* SQL-286: insufficient page size for CREATE TABLE
 
* SQL-286: insufficient page size for CREATE TABLE
 
* SQL-530: foreign key violation
 
* SQL-530: foreign key violation

Revision as of 01:23, 12 August 2008

MySQL Tips

Table Name Case Sensitivity

If you use Linux or Unix for your MySQL server, the table names may be case sensitive, so PRODUCT and product are not the same table. You can turn this off by configuring mysqld on startup to ignore table names with the lower-case-table-names flag, such as this example from /etc/init.d/mysql:

 $bindir/mysqld_safe --datadir=$datadir --lower-case-table-names=1 --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
     

See MySQL manual on identifier case sentivity

UTF-8 Support

By default, MySQL supports the Latin1 character set, which is intended for European languages such as English. If you wish to use MySQL for other language types, you may need to set up a database or UTF-8 character set encoding. To do this, you would need to create your database using UTF-8 first:

   mysql> create database opentaps default character set utf8 collate utf8_general_ci;

Then you would need to set your framework/entity/config/entityengine.xml file for the MySQL database to use the UTF-8 character set:

            character-set="utf8"
            collate="utf8_general_ci" 

Note that it is not clear that my SQL supports case sensitive UTF-8 coalition at this point, although you may be able to use UTF-8 binary collation.

DB2 Tips

You must configure DB2 to have tablespaces of 8K or more. This can be done when you create the database from the Control Center:


If you get an error message from DB2, you will get a SQLCODE like below:

DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=63, DRIVER=3.50.152

To figure out what it is, you have to run db2 from the command line:

$ db2 ? sql-530

Some of the more popular codes are:

  • SQL-204: <name> not recognized. Most likely, you are referencing a table that doesn't exist.
  • SQL-270: Function not supported. See the SQLERRMC for the message code.
  • SQL-286: insufficient page size for CREATE TABLE
  • SQL-530: foreign key violation

Check Valid DB2 field types for correct field types.

DB2 does not support scrollable resultsets for certain data types (see [1]).