cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using Mega API to update "DataTypes"

mrajih
Super Contributor

Hello,

 

I would like to use Mega API with VBS to update colonnes datatypes.

The targeted DB version is MySql.

 

If I user the regulare code, I got this error ("VARCHAR" is out of range) :

 

#######################################

If field.getAttribute("type") = "string" then
 oCol.SetProp "Data Type", "VARCHAR"
ElseIf field.getAttribute("type") = "date" then
 oCol.SetProp "Data Type", "DATE"
ElseIf field.getAttribute("type") = "text_general" then
 oCol.SetProp "Data Type", "TEXT"
End If

#######################################

 

Thanks

Mehdi

2 Replies

mrajih
Super Contributor

Hello,

 

I received a solution for this issue, so I'm posting it to help the next one facing the same problem :

 

To update a column dataytpe, we need to update the link between them, as this is a legattribut.

Ex : 

We can link directly datatype « MySQL 5.0 ::TEXT » to a column:

GetObjectFromID("~fXaL8560P1Hk[Catalog_Code]").SetProp "~7MmfquSJxya0[Datatype]", "~(q(Y39ye4Dy5[TEXT]"

Ou :

"~fXaL8560P1Hk[Catalog_Code]" : Column ID in my repository

"~7MmfquSJxya0[Datatype]" : ID of the link Column \Datatype

"~(q(Y39ye4Dy5[TEXT]" :  Datatype ID of « TEXT » for the SGBD « MySQL 5.0 » .

 

To avoid dealing with different SGBD versions, especially after migrations « MySQL 4.0 » to « MySQL 5.0 », it's better to use Pivot :

GetObjectFromID("~fXaL8560P1Hk[Catalog_Code]").SetProp "~7MmfquSJxya0[Datatype]", "~rJuMkwrhx020[P-Text]"

Or :

"~rJuMkwrhx020[P-Text]" : Pivot ID «P-Text ».

 

so in my case the new code looks like this :

 

###############################################################

oCol.SetProp "UNIL - DataType", field.getAttribute("type")
If field.getAttribute("type") = "string" then
   oCol.SetProp "~7MmfquSJxya0[Datatype]", "~rJuMkwrhx020[P-Text]"
ElseIf field.getAttribute("type") = "date" then 
   oCol.SetProp "~7MmfquSJxya0[Datatype]", "~Dq(4meHjuKT0[P-Date]"
ElseIf field.getAttribute("type") = "text_general" then
   oCol.SetProp "~7MmfquSJxya0[Datatype]", "~h2H23l055bc0[P-Longtext]"
End If

###############################################################

 

Hope this help

 

Mehdi

mrajih
Super Contributor

Hello

 

I updated my code as this :

 

#################################

If field.getAttribute("type") = "string" then
oCol.SetProp "DataType", "V"
ElseIf field.getAttribute("type") = "date" then
oCol.SetProp "DataType", "D"
ElseIf field.getAttribute("type") = "text_general" then
oCol.SetProp "DataType", "W"
End If

#################################

 

I dont get any error message but still no update on the objects.

 

Anyone can help ?

 

Thanks