Navigation:  Database Support > Converting Between Databases >

Datatype Conversion

Previous pageReturn to chapter overviewNext page

When a new target database is selected, one of the steps that ModelRight 3 takes is to convert the datatypes (if needed).   The Convert Datatype Script is used to accomplish this.   Its code looks something like:

  Select Case PrevDatabase ' what was the previous database type

      Case "MySQL 5.0", "MySQL 5.1"

          Select Case CurDatatypeName ' what was the name of the previous datatype

                  Case "TINYINT", "BOOL", "BOOLEAN", "SMALLINT"

                      NewDatatype = "SMALLINT" ' specify the new datatype name

                       .

                       .

                       .

                  Case Else

                          ' dont change it - let the datatype get deleted while still being used.

                          ' the app will let you know by issueing a warning - and inherit a default value

                      NewDatatype = ""

          End Select

      Case Else

          Document.Write("Unknown Previous Database")

          Exit Sub

  End Select

  If NewDatatype <> "" Then

      Obj.SetDatatype(NewDatatype) ' call SetDatatype to change the current objects datatype

  End If

  Document.Write("Ok") ' return Ok, or something else to flag an error

 

The advantage of this approach is that the Script could contain any sort of coding logic that you might want to use to determine the new datatype.  You could look at what the current object is that is having its datatype changed.  You could look at the length of the datatype and use that to determine the new datatype.  etc...

If you are converting from Oracle to another type of database, any Tables or Columns that use an Object Type will be converted to have the Object Type's Attributes represented as ordinary Columns.

As with any ModelRight 3 Script, you can use the existing one, or change it for an individual object, the entire model, or all models.  See Scripting for more details.

 


Page url: http://www.modelright.com