Re: ERXSQLHelper
Re: ERXSQLHelper
- Subject: Re: ERXSQLHelper
- From: OC <email@hidden>
- Date: Mon, 12 Jan 2015 23:18:41 +0100
P.S. my current environment is
Groovy 2.3.8 / WebObjects 5.4.3 / ERExtensions 6.1.2-SNAPSHOT / Java 1.7.0_13 / Mac OS X 10.8.5 / FrontBase 7.2
On 12. 1. 2015, at 22:56, OC <email@hidden> wrote:
> Theodore,
>
> On 12. 1. 2015, at 19:00, Theodore Petrosky <email@hidden> wrote:
>> have you looked at the migrations?
>> ERXMigrationTable personTable = database.existingTableNamed("person");
>> personTable.existingColumnNamed("Foo").renameTo("Bar”);
>> personTable.newStringColumn(name, width, allowsNull)
>
> well... the API looks OK, but in practice it does not seem quite work. Can you (or anybody knowledgeable) please point out what am I doing wrong? Here's my code (sans error checking etc. for better readability)
>
> ===
> EOObjectStoreCoordinator osc=EOObjectStoreCoordinator.defaultCoordinator()
> EODatabaseContext ctxt=ERXEOAccessUtilities.databaseContextForEntityNamed(osc,'DBAuction')
> ctxt.lock();
> try {
> EOAdaptorChannel ach = ctxt.availableChannel().adaptorChannel();
> if (!ach.isOpen()) ach.openChannel();
> def tables=ach.describeTableNames() // looks like Migration API does not read the current state reliably
> EOModel dbModel=ach.describeModelWithTableNames(tables)
> ERXMigrationDatabase mdb=nil // created on-demand
> mdg.models.each { EOModel localModel ->
> localModel.entities.each { EOEntity localEntity ->
> if (localEntity.isAbstractEntity()) return
> String tname=localEntity.externalName()
> EOEntity dbEntity=dbModel.entityNamed(tname)
> ERXMigrationTable mtable=nil // on-demand
> localEntity.attributes.each { EOAttribute localAttribute ->
> String cname=localAttribute.columnName()
> EOAttribute dbAttribute=dbEntity.attributeNamed(cname)
> if (!dbAttribute) {
> println " adding column $cname ($localAttribute.name): $localAttribute.externalType (VT: $localAttribute.valueType) ..."
> if (!mdb) mdb=ERXMigrationDatabase.database(ach)
> if (!mtable) mtable=mdb.existingTableNamed(tname)
> switch (localAttribute.externalType) {
> ...
> case 'TIMESTAMP':
> mtable.newTimestampColumn(cname,YES)
> break
> }
> println " - OK"
> }
> }
> }
> }
> } finally {
> ctxt.unlock()
> }
> ===
>
> but it crashes, printing out
>
> ===
> adding column DC_ID (ID): TIMESTAMP (VT: null) ...
> 22:42:09.409 INFO Executing alter table T_AUCTION null DC_ID TIMESTAMP //log:er.extensions.jdbc.ERXJDBCUtilities [main]
> ...
> Caused by: java.lang.RuntimeException: Failed to execute 'alter table T_AUCTION null DC_ID TIMESTAMP'.
> Caused by: java.sql.SQLException: Syntax error 179. Illegal ALTER TABLE statement.
> ===
>
> Well self-evidently it _is_ an illegal statement, it lacks "add column" having "null" instead; but what's the culprit and how to fix the problem?
>
> (Note: I've tried to bump up log levels to
> log4j.logger.er.extensions.jdbc.ERXJDBCUtilities=TRACE
> log4j.logger.er.extensions.migration.ERXMigrationDatabase=TRACE
> log4j.logger.er.extensions.migration.ERXMigrationTable=TRACE
> log4j.logger.er.extensions.migration.ERXMigrationColumn=TRACE
> but no more logs occurred anyway.)
>
> Thanks,
> OC
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden