views:

291

answers:

2

Hello,

Probably I'm doing something wrong but here it goes:

I'm trying to create a database using subsonic.migrations in an OracleXE version 10.2.0.1.0. I have ODP v 10.2.0.2.20 installed.

This is my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" requirePermission="false"/>
  </configSections>

  <connectionStrings>
    <add name="test" connectionString="Data Source=XE; User Id=test; Password=test;"/>
  </connectionStrings>

  <SubSonicService defaultProvider="test">
    <providers>
      <clear/>
      <add name="test" type="SubSonic.OracleDataProvider, SubSonic" connectionStringName="test" generatedNamespace="testdb"/>
    </providers>
  </SubSonicService>

</configuration>

And that's my first migration:

public class Migration001_Init : Migration {

        public override void Up() {

            //Create the records table
            TableSchema.Table records = CreateTable("asdf");
            records.AddColumn("RecordName");
       }

        public override void Down() {
            DropTable("asdf");
        }
    }

When I run the sonic.exe, I get this exception:

Setting ConfigPath: 'App.config'
Building configuration from D:\Users\carlucci\Documents\Visual Studio 2008\Projects\Wum\Wum.Migration\App.config
Adding connection to test
ERROR: Trying to execute migrate
Error Message: System.Data.OracleClient.OracleException: ORA-02253: especifica‡Æo de restri‡Æo nÆo permitida aqui

   at System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)
   at System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor)
   at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
   at SubSonic.OracleDataProvider.ExecuteQuery(QueryCommand qry) in D:\@SubSonic\SubSonic\SubSonic\DataProviders\OracleDataProvider.cs:line 350
   at SubSonic.DataService.ExecuteQuery(QueryCommand cmd) in D:\@SubSonic\SubSonic\SubSonic\DataProviders\DataService.cs:line 544
   at SubSonic.Migrations.Migrator.CreateSchemaInfo(String providerName) in D:\@SubSonic\SubSonic\SubSonic.Migrations\Migrator.cs:line 249
   at SubSonic.Migrations.Migrator.GetCurrentVersion(String providerName) in D:\@SubSonic\SubSonic\SubSonic.Migrations\Migrator.cs:line 232
   at SubSonic.Migrations.Migrator.Migrate(String providerName, String migrationDirectory, Nullable`1 toVersion) in D:\@SubSonic\SubSonic\SubSonic.Migrations\Migrator.cs:line 50
   at SubSonic.SubCommander.Program.Migrate() in D:\@SubSonic\SubSonic\SubCommander\Program.cs:line 264
   at SubSonic.SubCommander.Program.Main(String[] args) in D:\@SubSonic\SubSonic\SubCommander\Program.cs:line 90
Execution Time: 379ms

What am I doing wrong?

Thanks a lot for any help :)

Andre Carlucci

UPDATE: As pointed by Anton, the problem is the subsonic OracleSqlGenerator. It is trying to create the schema table using this sql:

CREATE TABLE SubSonicSchemaInfo (
       version int NOT NULL CONSTRAINT DF_SubSonicSchemaInfo_version DEFAULT (0)
)

Which doesn't work on oracle. The correct sql would be:

CREATE TABLE SubSonicSchemaInfo (
  version int DEFAULT (0),
  constraint DF_SubSonicSchemaInfo_version primary key (version)
)

The funny thing is that since this is the very first sql executed by subsonic migrations, NOBODY EVER TESTED it on oracle.

+1  A: 

Just a wild guess (I'm not exactly aware about precise CREATE TABLE syntax for Oracle): SubSonic attempts to create a "Schema Info" table (see this, search for private static void CreateSchemaInfo(string providerName)) with "0" being the default value. Internally it uses OracleGenerator which is basically an ANSIGenerator, so this might be the problem.

Anton Gogolev
You are right! I did a step by step debug and could see that subsonic is using a SQL completely alien to oracle. Thank you!
andrecarlucci
A: 

This is my fault. I don't have a license for Oracle nor do I have the slightest clue on how it works. What I tried to do (with respect to SQL generation) was to have a base class that generates ANSI-compliant SQL (yah, I know - but a guy can dream) with virtual methods that each provider can tweak as needed.

Eric and others (who use Oracle) tested out most of the queries etc - but you're correct - we never had a chance to test Migrations on Oracle. This is my fault and I take responsibility. I need to take some time to get to know Oracle - or find a committer willing to devote more time here.

Rob Conery
That's also you fault that subsonic exists and let's be honest, it really rocks. About oracle, you can download oracle express (http://www.oracle.com/technology/products/database/xe/index.html), it's the free version for development and it has all the features you need. I'll take a look on this anyway, cheers!
andrecarlucci