Symfony 2.8 with Oracle Database - Identifier is too long - php

I'm trying to configure phpcr_odm with Symfony 2.8 using Oracle database from
this link. When I'm trying to run php app/console doctrine:schema:create my console returns error
[Doctrine\DBAL\Exception\DriverException]
An exception occurred while executing 'CREATE UNIQUE INDEX UNIQ_37E65615460D9FD7413BC13C1AC10DC4E7087E10 ON phpc
r_binarydata (node_id, property_name, workspace_name, idx)':
ORA-00972: identifier is too long
[Doctrine\DBAL\Driver\OCI8\OCI8Exception]
ORA-00972: identifier is too long
I know that Oracle SQL limits unique indexes for 30 chars but I don't know how to limit unique indexes before they are executed in symfony. Can somebody please tell me how to fix this issue ?
Best Regards

If you declare the unique constraint on your entity yourself you can set its name manually:
#ORM\Table(name="phpcr_binarydata", uniqueConstraints={#ORM\UniqueConstraint(name="SMALL_KEY_NAME_HERE", columns={"node_id", "property_name", "workspace_name", "idx"})})
If the database creation is not under your control the maximum identifier length is configured in Doctrine\DBAL\Schema\SchemaConfig::$maxIdentifierLength which you could try to extend and override.

In SQL-92 the later version of the standard appears to optionally allow for 128 character names. Otherwise this would be the solution: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/AbstractAsset.php#L219

Related

Doctrine2/DBAL + Postgresql - public. schema missing in Doctrine queries | Empty query's result

on my VPS server queires Doctrine's query responsible for counting executed migrations returns no rows. Problem is weird, using PHPStorm sometimes I also got no results but it happens only when I skip public. schema. I can't set in Doctrine's config table name with public. prefix due to further DBAL problems. Localy I got same version of PgSQL 9.6 and PHP 5.6, onle difference #VPS is PHP 7.1.
#------------------------------------------------------------------------------
# CLIENT CONNECTION DEFAULTS
#------------------------------------------------------------------------------
# - Statement Behavior -
#search_path = '"$user", public' # schema names
#default_tablespace = '' # a tablespace name, '' uses the default
#temp_tablespaces = '' # a list of tablespace names, '' uses
Changing search_path helps partialy, it sometimes causes rows to appear as query's result however Doctrine migration still has problem with it.
Queries:
SELECT * FROM doctrine_migration_versions; -- sometimes no results, even if ros actually exists
SELECT * FROM public.doctrine_migration_versions; -- works always
Thanks in advance for any answears.
I found the problem. Problem was that database user was the same as existing schema. That's why Postgres by default was looking for user named schema and it found it. Changing postgres conf to do not look for user but public. schema only, solved 'problem'
#search_path = '"$user", public' # schema names
to
search_path = 'public' # schema names

Why does Doctrine generate different constraint names?

I am using Symfony2 with Doctrine to generate my MySQL tables. Usually, Doctrine is able to update the database quite easily.
The MySQL server is on a linux machine. There is also an Apache running which hosts my Symfony application. When running php app/console doctrine:schema:update --dump-sql on the Linux machine Doctrine tells me that my database is up to date.
However, when running this command on Windows on the exact same Symfony application and connecting to the MySQL server on the Windows machine, Doctrine wants to change quite a few of the constraint names. It seems that it wants to rename all the indices:
DROP INDEX idx_2d91b64f56629d6d ON table1;
CREATE INDEX IDX_13241BA356629D6D ON table1 (col1_id);
DROP INDEX idx_2d91b64fbad26311 ON table1;
CREATE INDEX IDX_13241BA3BAD26311 ON table1 (col2_id);
DROP INDEX idx_bc100bf27dc308 ON table2;
CREATE INDEX IDX_8C245317DC308 ON table2 (col3_id);
// some more similar lines omitted
Why does this happen? I had a look at how Symfony generates the constraint names and it is using dechex and crc32, both of which should be platform-independent.
This may not be the cause, but it does look like a possible cause:
http://php.net/manual/en/function.crc32.php
In the red section, it states that crc32 can return negative or positive values depending on 32 or 64 bit systems.
This is because of the range of a 32 signed integer: −2,147,483,648 to 2,147,483,647.
If you take from this that crc32 assumes to work with unsigned bytes, any value it produces over 2,147,483,647 will become negative.
Then dechex will produce a hexadecimal value based on the decimal value, negative or possible.

does map collection type support in cassandra 2.0

when i create table in cassandra 2.0 using phpcassa,i got the error as follows
Fatal error: Uncaught exception 'cassandra\InvalidRequestException' with message 'line 2:25 mismatched input 'map' expecting set null' in /var/www/assignment1/lib/thrift/Thrift.php:574
my code goes as
$raw->client->execute_cql_query("CREATE TABLE
mc_user(mc_user_id uuid primary key ,mc_user_email varchar,mc_user_pwd varchar,mc_status varchar,mc_user_type map<varchar,varchar>)", Compression::NONE);
if it doesnt supports does anyone can give me alternative solution for one to many relation?
Collections are definitely supported in Cassandra since version 1.2 - I don't know PHP Cassa however your statement looks correct so I'd look on the client side for the solution.
An alternative could be using a composite key in which the second part of the key is the key you wanted use in the map
CREATE TABLE mc_user(
mc_user_id uuid,
themapkey varchar,
mc_user_email varchar static,
mc_user_pwd varchar static,
mc_status varchar static,
themapvalue varchar,
PRIMARY KEY (mc_user_id, themapkey)
);
Now instead of having one entry per user with a map, you have many entries per user.
I've made the email, password and status static since they should be the same for each mc_user_id (two main advantages comes in my mind: they are not replicated in each row so they won't waste disk space and you can update them easily just with 1 update statement since static columns are accessible only by partition key).
You can still retrieve user's information (now static) only with mc_user_id
select mc_user_email, mc_status from mc_user where mc_user_id=some_id
You can retrieve a "map" entry with mc_user_id, themapkey
select themapvalue from mc_user where mc_user_id=some_id and themapkey=some_key
You can also easily rebuild all map with a select *
select * from mc_user where mc_user_id=some_id
HTH
Cheers,
Carlo
Can try to use this library. It does not require Trift and works using the binary protocol.

Renaming a column in a migration script in Doctrine2

When I have a Table reference and I call renameColumn() on it, I get the following pair of errors:
Migration 20130725141653 failed during Execution. Error Table#renameColumn() was removed, because it drops and recreates the column instead. There is no fix available, because a schema diff cannot reliably detect if a column was renamed or one column was created and another one dropped.
[Doctrine\DBAL\DBALException]
Table#renameColumn() was removed, because it drops and recreates the column instead. There is no fix available, because a schema diff cannot reliably detect if a column was renamed or one column was created and another one dropped.
(executed via doctrine migrations:migrate --dry-run)
Which makes sense... for a diff program.
I'm writing a migration. I know that I want the column renamed (preserving data).
Is there any pure Doctrine method (I don't want to write a raw query) to acheive this?
The 'diff' that the exception is talking about is the diff between your original Schema and your updated Schema. This is how Doctrine generates the SQL statements -- by comparing the current Schema to the modified Schema.
There is no way for Doctrine to reliably figure out that someColumn in $originalTable is now someRenamedColumn in $modifiedTable (pardon the bad psuedocode) and so the functionality was removed .

postgresql sequence problems with lastinsertid and zend framework

I have just started working on a project and I am using zend framework and postgresql (normally use MySQL) however I am hitting a problem when I am trying to get the last inserted id when using the Zend_Db insert command.
When using the function $db->lastinsertid('users', 'userid'); I get the following error message:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "users_userid_seq" does not exist LINE 1: SELECT CURRVAL('users_userid_seq') ^
I've checked the database and the sequence does exist, and both the table and the sequence is owned by the the same user that is being use to access the application.
I've even tried $db->lastSequenceId('users_userid_seq'); but still get the same error message.
I am not sure if the problem is with postgresql (I think most likely) or with the framework.
Has anyone else had a similar problem to this?
I see you found your answer, it was simply a typographical error.
FWIW, I'll offer the following suggestion as another reason for the error you saw:
You need to spell the name of the sequence exactly as it is stored, including matching case if the sequence name is stored as anything other than lower-case.
In other words, if the sequence was created with the spelling "Users_userid_seq," but you queried it as "users_userid_seq," this doesn't match and you'll get the error.
Try listing sequences in the psql tool:
postgres=# \ds
This will show you the sequences defined, with their spelling as they are stored in the database.
Check if the schema of the table "users" is in the "search_path" of the Zend_Db session.
The field "userid" is a primary key in the table "users" ?
If it's not, change the userid type.
The following code works for me (PostgreSQL & Zf):
$db->insert($this->getTableName(), $data);
$id = $db->lastSequenceId($this->_sequence);
Replace $this->_sequence with the sequence you are using in the database.

Categories