• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ERXSQLHelper
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ERXSQLHelper


  • Subject: Re: ERXSQLHelper
  • From: OC <email@hidden>
  • Date: Mon, 12 Jan 2015 22:56:57 +0100

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


  • Follow-Ups:
    • Re: ERXSQLHelper
      • From: OC <email@hidden>
References: 
 >ERXSQLHelper (From: OC <email@hidden>)
 >Re: ERXSQLHelper (From: Theodore Petrosky <email@hidden>)

  • Prev by Date: Re: ERXSQLHelper
  • Next by Date: Re: ERXSQLHelper
  • Previous by thread: Re: ERXSQLHelper
  • Next by thread: Re: ERXSQLHelper
  • Index(es):
    • Date
    • Thread