Il y a une erreur dans le codage qui néanmoins ne déclenche pas une message
si l'on l'exécute:
En deux cas il y a la ligne:

pierre-yves samyn wrote
> oDescCol.Type = com.sun.star.sdbcx.KeyType.FOREIGN

Cette constante n'est pas correcte pour une colonne, on aura besoin d'une
constante du type com.sun.star.sdbc.DataType.... La valeur de la constante
est 3, donc le „Type“ de la colonne en ton cas est DECIMAL.

En essayant de créer une *nouvelle* table je suis arrivé aux mêmes
instructions. Il y a seulement une chose à observer dans cette situation: On
doit (avec LibreOffice 4.2 au moins) d'abord créer la table (avec le PRIMARY
KEY, ça fonctionne), et puis ajouter la FOREIGN KEY à l'objet table.

Mon exemple (testé avec MySQL/MariaDB):

tableDescr = tables.createDataDescriptor
tableDescr.Name = "textmodule"

keyDescr = tableDescr.Keys.createDataDescriptor
keyDescr.Name = "Primary Key"
keyDescr.Type = com.sun.star.sdbcx.KeyType.PRIMARY

colDescr = tableDescr.Columns.createDataDescriptor
colDescr.Name = "seg"
colDescr.Type = com.sun.star.sdbc.DataType.CHAR
colDescr.Precision = 4
tableDescr.Columns.appendByDescriptor(colDescr)
keyDescr.Columns.appendByDescriptor(colDescr)

colDescr = tableDescr.Columns.createDataDescriptor
colDescr.Name = "textno"
colDescr.Type = com.sun.star.sdbc.DataType.TINYINT
colDescr.Precision = 6
tableDescr.Columns.appendByDescriptor(colDescr)
keyDescr.Columns.appendByDescriptor(colDescr)

colDescr = tableDescr.Columns.createDataDescriptor
colDescr.Name = "textdefinition"
colDescr.Type = com.sun.star.sdbc.DataType.VARCHAR
colDescr.Precision = 255
tableDescr.Columns.appendByDescriptor(colDescr)
tableDescr.Keys.appendByDescriptor(keyDescr)

'       this creates the table:
tables.appendByDescriptor(tableDescr)

'       Now create the foreign Key:
table = tables.getByName("textmodule")
keyDescr2 = table.Keys.createDataDescriptor
keyDescr2.Name = "FK_textmodule_segment"
keyDescr2.Type = com.sun.star.sdbcx.KeyType.FOREIGN
keyDescr2.DeleteRule = com.sun.star.sdbc.KeyRule.RESTRICT
keyDescr2.UpdateRule = com.sun.star.sdbc.KeyRule.RESTRICT
keyDescr2.ReferencedTable = "segment"
colDescr2 = keyDescr2.Columns.createDataDescriptor
colDescr2.Name = "seg"  'column in this table
colDescr2.Type = com.sun.star.sdbc.DataType.CHAR
colDescr2.Precision = 4
colDescr2.relatedColumn = "segment"     'column of the referenced table
keyDescr2.Columns.appendByDescriptor(colDescr2)
table.Keys.appendByDescriptor(keyDescr2)

Seulement le nom du clé  n'est oas arrivé à la base de données, il y a un
nom généré: textmodule_ibfk_1

Gerhard




--
View this message in context: 
http://nabble.documentfoundation.org/Supprimer-creer-des-relations-entre-tables-par-macro-tp4102110p4128918.html
Sent from the Users mailing list archive at Nabble.com.

-- 
Envoyez un mail à users+unsubscr...@fr.libreoffice.org pour savoir comment vous 
désinscrire
Les archives de la liste sont disponibles à 
http://listarchives.libreoffice.org/fr/users/
Tous les messages envoyés sur cette liste seront archivés publiquement et ne 
pourront pas être supprimés

Répondre à