JdbcSQLException executing PostgreSQL query with 'MATCH simple' in H2 - spring

I'm trying to run in development mode (with H2) a setup currently used in production with a PostgreSQL database and I get an error. It would be best if I could reuse the production SQL without any change to it.
Using this setup:
# H2 Database
spring.datasource.datasource-class-name=org.h2.jdbcx.JdbcDataSource
spring.datasource.url=jdbc:h2:mem:userregistry;DB_CLOSE_DELAY=-1;MODE=PostgreSQL
This query:
CREATE TABLE IF NOT EXISTS users.user_userrole (
user_signum VARCHAR(20) NOT NULL,
role VARCHAR(255) NOT NULL,
CONSTRAINT user_userrole_pk PRIMARY KEY (user_signum, role),
CONSTRAINT user_fk FOREIGN KEY (user_signum) REFERENCES users.user (signum) MATCH SIMPLE,
CONSTRAINT role_fk FOREIGN KEY (role) REFERENCES users.userrole
(role_name) MATCH SIMPLE
);
Raises this exception:
org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "<<SQL OMITTED FOR BREVITY>>";
expected "INDEX, ON, NOT, DEFERRABLE, NOCHECK, CHECK, ,, )"; [42001-185]
Note that I am already using Mode=PostgreSQL. Any ideas?
Thanks

The H2 database does not support MATCH SIMPLE (same as Oracle, MS SQL Server, Apache Derby).

Related

Cannot insert NULL into table

I'm using EF Core to connect to an Oracle11g database (using the Oracle.EntityFrameworkCore v2.19.90 provider). It's a code first scenario, the tables are created successfully and everything is as expected.
The problem is, when I try to insert something into the database, for example:
_context.Roles.Add(new ApplicationRole()
{
Name = "FOO",
DisplayName = "Foo"
});
_context.SaveChanges();
I get an error:
OracleException: ORA-01400: cannot insert NULL into ("SCHEMA"."AppRole"."Id")
The column Id is indeed non-nullable. When I use the SQL Server provider, everything is fine, the SQL Server automatically chooses an id for my entity.
Is there any way to get Oracle to set an Id for me? Or could it be done in another way?
I don't want to use Oracle triggers and the solution should be full code first.
As you're on Oracle 11g, then you have to use a trigger along with a sequence which will populate ID column in the background.
Another option is to, obviously, provide ID value during insert.
If you were on 12c or above, you could have used identity column. As you're not, your options are listed above.
One option may be usage of SEQUENCE and default value:
CREATE TABLE AppRole(
Id INT NOT NULL,
Name VARCHAR2(100),
DisplayName VARCHAR2(100)
);
CREATE SEQUENCE seq;
ALTER TABLE AppRole MODIFY Id DEFAULT seq.NEXTVAL;
INSERT INTO AppRole(Name, DisplayName) VALUES ('Foo','Foo');
db<>fiddle demo
Default with sequence is supported from Oracle 12c.
There should exist syntax in EntityFramework core that allow to do the following without relying on triggers(raw SQL query as last resort):
INSERT INTO AppRole(Id, Name, DisplayName) VALUES (seq.NextVal, 'Foo','Foo');
Sequences
Basic usage
You can set up a sequence in the model, and then use it to generate
values for properties: C#
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasSequence<int>("OrderNumbers");
modelBuilder.Entity<Order>()
.Property(o => o.OrderNo)
.HasDefaultValueSql("NEXT VALUE FOR shared.OrderNumbers");
}
Note that the specific SQL used to generate a value from a sequence is
database-specific; the above example works on SQL Server but will fail
on other databases. Consult your specific database's documentation for
more information.
Oracle syntax is sequence_name.NEXTVAL.

Exception when attempting to create the jdbc tables

When connecting to Amazon RDS MySQL Aurora the lagom service throws an exception when attempting to create the jdbc tables
2018-01-16T00:11:32.891Z [[31merror[0m] akka.actor.OneForOneStrategy
[sourceThread=userservice-v1-akka.actor.default-dispatcher-18, akkaTimestamp=
00:11:32.877UTC, akkaSource=akka://userservice-v1/user/slickOffsetStorePrepare-singleton/singleton/slickOffsetStorePrepare,
sourceActorSystem=userservice-v1] - You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to use near '"read_side_offsets" ("read_side_id" VARCHAR(255) NOT NULL,"tag" VARCHAR(255) NOT' at line 1 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near '"read_side_offsets" ("read_side_id" VARCHAR(255) NOT NULL,"tag" VARCHAR(255) NOT' at line 1
2018-01-16T00:11:32.896Z [[31merror[0m] akka.actor.OneForOneStrategy
[sourceThread=userservice-v1-akka.actor.default-dispatcher-20, akkaTimestamp=
00:11:32.885UTC, akkaSource=akka://userservice-v1/user/jdbcCreateTables-singleton/singleton/jdbcCreateTables,
sourceActorSystem=userservice-v1] - You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax to use near
'"journal" ("ordering" BIGINT AUTO_INCREMENT NOT NULL,"deleted" BOOLEAN DEFAULT f'
at line 1 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '"journal" ("ordering" BIGINT
AUTO_INCREMENT NOT NULL,"deleted" BOOLEAN DEFAULT f' at line 1
I haven't been able to find if this is a known issue of a configuration element that I'm missing.
Ensure that you've selected the correct Slick driver for your database as described in the Lagom documentation on Relational Database Persistent Entities:
jdbc-defaults.slick.driver = "slick.driver.MySQLDriver$"

I am unable to create table in MySql (Error 1064)

While I am creating a table In MySql, I am getting an error. I don't know What the problem is, but it will be helpful if I understand the reason behinId it.
Query:
create table publish(
From varcahar(60),
To varchar(60)
);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'From varcahar(60),To varchar(60))' at line 1
Several errors:
1.- From and To are reserverd words you need to escape them
2.- varcahr -> varchar
Final code:
create table publish(
`From` varchar(60),
`To` varchar(60)
);
It says varcahr(60) not varchar(60)
Spelling problem
create table publish(From varchar(60),To varchar(60));
This is the right one. You misspelled varchar
And also From and To are reserved words. Check this Reserved Words In MySql

IONIZE CMS post installation problem

I decided to try Ionize cms which is build over CodeIgnitor. I have my apache, php , mysql installed seperately. When I finished installing the cms successfully, I cannot access the website. Some weird errors occurs like
Call to a member function num_rows() on a non-object in ... \ionize-0.9\application\models\article_model.php on line 224
I got frustated and searched many places. Later I tested the CMS in WAMP, and there it worked.
Now I have no idea, what is going on, everything the CMS needs to run, is tested during the installation. I dont have any idea.... how to solve it. Please help me
For one unknown reason, all the tables of the database weren't installed. Ionize currently doesn't check that situation. If it works on one server (Wamp) and not on one other (manually LAMP installed server), compare the tables list on each system.
I had this same issue on a WAMP server and the reason was that it couldn't created the article_type table.
I'd suggest checking your database to see if that table exist.
If it doesn't take a look at the data.sql file and try to run only that create table section. It should spit out an error. In my case the description text NOT NULL default "" was throwing an error (BLOB/TEXT column 'description can't have a default value).
I fixed it by making sure description doesn't have a default value.
CREATE TABLE IF NOT EXISTS article_type (
id_type int(11) unsigned NOT NULL auto_increment,
type varchar(50) collate utf8_unicode_ci NOT NULL,
ordering int(11) default 0,
description text NOT NULL,
type_flag TINYINT( 1 ) NOT NULL default 0,
PRIMARY KEY (id_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 COMMENT='0.9.7';

Autoincrement syntax error

The Sybase manual and plenty of examples claim I can write:
create table run_log (
run_id integer not null default autoincrement
);
But Sybase 15 says there is a syntax error on the default
Sybase documentation isn't great, and it turns out there's Sybase ASA, some other product they bought, and Sybase ASE (Server Enterprise) which is what most people would think of as Sybase.
For ASE15, it's not autoincrement, it's identity, which must be on numeric, not integer
create table run_log (
runid numeric(12,0) identity
)

Resources