Using NDbUnit with tables that have a table schema - ndbunit

I am having issues using NDbUnit with tables that have their own schema - ie:
CREATE TABLE MYSCHEMA.MyTable01
(
Id int NOT NULL,
Description varchar(50) NOT NULL
)
Is this a supported scenario? What do I need to do to get this to work?
(working fine when the table is dbo.MyTable01)

What version of NDbUnit are you using? Earlier releases failed to support explicit schema prefixes but the more recent releases should properly support them.

Related

How to check database schema in swift?

I'm using SQLite.Swift and I'd like to know how to do to verify that the db still has the same schema when the application starts because on updtate, it's possible that the new application add columns in the table in which case I'm unable to use the existing db on the device.
I'll have to migrate/recreate the table.
How to do that please?
For tracking the database version, you can use the built in user-version variable that sqlite provides (sqlite does nothing with this variable, you are free to use it however you please). It starts at 0, and you can get/set this variable with the following sqlite statements:
> PRAGMA user_version;
> PRAGMA user_version = 1;
See this answer which discuss your requirement including making schema changes after update

Syntax error in creating trigger in sqlite

The following code causes a syntax error in SQLite.
I imagine this must be simple but I can't see it.
I have two tables, pages and items, linked through a text code. When this code in changed in pages table, I want it changed in items table too.
The SQLite version is quite old, 3.7.7.1, but I haven't seen such a problem in version history. This occurs on Windows, with PHP 5.3.1.
CREATE TABLE IF NOT EXISTS "efpage" ( "pageid" integer NOT NULL PRIMARY KEY, "psite" text NULL, "pgcode" text NULL );
CREATE TABLE IF NOT EXISTS "efitem" ( "itemid" integer NULL PRIMARY KEY , "isite" text NULL, "ititle" text NULL, "inpage" text NULL);
DROP TRIGGER IF EXISTS update_pagecode;
CREATE TRIGGER update_pagecode AFTER UPDATE OF pgcode ON efpage
BEGIN
UPDATE efitem SET inpage = new.pgcode WHERE inpage = old.pgcode;
END;
The resulting error is
ERROR near "pgcode": syntax error.
Trying different things, I saw that the syntax error is after "old.pgcode;"
As indicated by CL,
this is linked to the version of SQLite.
I use SQLite bundled with PHP on windows.
The next (answered) question for me is :
How to update the SQLite version bundled with PHP

How to use variables in sqlite

Created the following code in SQL however need to use it in sqlite (phonegap specifically).
INSERT INTO actions(Action) VALUES ('Go to the pub');
SET #aid = LAST_INSERT_ID();
INSERT INTO statements(statement, Language) VALUES ('Have a pint', 'English');
SET #sid = LAST_INSERT_ID();
INSERT INTO Relationships(SID,AID) VALUES (#sid,#aid);
The issue we are having however is how to declare the variables in sqlite.
The LAST_INSERT_ID() will become last_insert_rowid(), however what is the sqlite version of SET #aid = ?
SQLite does not have variables.
In an embedded database such as SQLite, there is no separate server machine or even process, so it would not make sense to add a programming language to the DB engine when the same control flow and processing logic could be just as well done in the application itself.
Just use three separate INSERT statements.
(In WebSQL, the result object has the insertId property.)

Is flyway database agnostic in its support for multiple databases?

Is Flyway suitable for implementation in an application that will support multiple databases?
We don't know what our customers are using - could be either MySQL, Postgres or Oracle. Can we still use Flyway to migrate the database for new versions of the application?
if your question is: does Flyway provide a DDL abstraction layer across the databases it supports, the answer is no.
This was a conscious design decision, to make sure the full power of the underlying database is available and not just the smallest common denominator supported by the migration tool.
For your use case, you could either provide different migration scripts for the different databases. They should be very similar though.
If you do not wish to potentially duplicate the migration scripts and can live with the smallest common denominator approach, have a look at LiquiBase which might be a better fit for your usecase (if you can live with the XML)
You could use jOOQ's parsing connection, which wraps your target JDBC connection and is capable of translating your input DDL to any target dialect (if it's not too fancy and vendor specific). Flyway wouldn't be aware of this translating JDBC proxy, and wouldn't have to be. The online version of the SQL translator can be seen here. For example, if your input SQL is a MySQL specific:
create table t (i int primary key auto_increment);
The output could be:
-- Oracle
create table T (
I number(10) generated by default as identity(start with 1) not null,
primary key (I)
);
-- SQL Server
create table T (
I int identity(1, 1) not null,
primary key (I)
)
-- PostgreSQL
create table T (
I int generated by default as identity not null,
primary key (I)
)
-- PostgreSQL 9.4
create table T (
I serial4 not null,
primary key (I)
)
Disclaimer: I work for the company behind jOOQ.

Sqlite: adding COMMENT ON descriptions to tables and columns?

In MySQL Workbench you can add COMMENTs to tables and columns in a MySQL database.
Does Sqlite support adding comments to tables and columns?
I don't think it does. The "SQL As Understood By SQLite" page makes no mention of table or column comments nor does the CREATE TABLE or ALTER TABLE documentation.
Also, the Unsupported SQL wiki page has this:
2009-08-04: Table and column comments - I have scoured the doco and can't find anything about applying comments to tables or their columns.
Yes, that's a wiki page from 2009 but that note is supported by the rest of the documentation.
However, SQLite does preserve SQL comments that you put in your DDL. If you feed this to the sqlite3 CLI tool:
CREATE TABLE User
-- A table comment
(
uid INTEGER, -- A field comment
flags INTEGER -- Another field comment
);
Then you get exactly that back from a .schema command:
sqlite> .schema
CREATE TABLE User
-- A table comment
(
uid INTEGER, -- A field comment
flags INTEGER -- Another field comment
);
So you should be able to fake it if you can control the DDL used to create your tables.
When creating a table using sqlite (I'm using sqlite3 in python), the COMMENT section is not supported.
This fails (works in full MySql syntax):
CREATE TABLE `Info` (
`Test` VARCHAR(512) NOT NULL COMMENT 'Column info here'
);
This works (no COMMENT in the column declaration):
CREATE TABLE `Info` (
`Test` VARCHAR(512) NOT NULL
);
(This isn't what the original poster was asking, but this is what I was looking for when I first found this question based on the keywords in the title.)
How to make comments in SQLite
There are two ways to make comments in SQLite code:
Hyphens
-- this is my comment
SELECT * FROM employees;
C-style
/* this is my comment */
SELECT * FROM employees;
I appreciate that this is an old post but for what it's worth, you can add comments when creating a table in SQLITE3, in Python and in Java. Probably works for other languages as well.
You need to add new lines to your sql string as you would if you were typing in the command at the SQLITE3 prompt -
sql_str = 'CREATE TABLE properties (\nproperty TEXT NOT NULL, -- A property\nvalue TEXT -- The value of the property\n);'
When executed the table is created like so:
sqlite> .schema
CREATE TABLE properties (
property TEXT NOT NULL, -- A property
value TEXT -- The value of the property
);
I suspect that this works because the connector is actually echoing in the commands via the command prompt, rather than some sort of API.

Resources