pydia SQL
- From: fitorec <chanerec gmail com>
- To: dia-list gnome org
- Subject: pydia SQL
- Date: Thu, 12 Aug 2010 12:04:59 -0500
Hello that such!, After a while of being programmed, finally finish
the sql dump.
My question now is: how I can extract relationships? In order to make
the foreign keys.
thanks in advance.
Source:
-----------------------------------------------------------------------------
# PyDia MySQL.py : SQL dump.
# Copyright (c) 2010 fitorec <chanerec gmail org>
import dia, sys, os, string
class MySqlRenderer :
def __init__ (self) :
self.f = None
def begin_render (self, data, filename) :
self.f = open(filename, "w")
name = os.path.split(filename)[1]
self.f.write ("-- DiaSql-Dump\n-- version 0.01\n-- Filename: %s\n" % (name,))
for layer in data.layers :
self.WriteTables (layer)
def WriteTables (self, layer) :
for o in layer.objects :
if o.type.name == 'Database - Table' :
if o.properties.has_key ("name") :
url = o.properties["name"].value
elif o.properties.has_key ("text") :
url = o.properties["text"].value.text
else :
continue
if len(url) == 0 or string.find (url, " ") >= 0 :
continue
self.f.write ('\n-- %s --\nCREATE TABLE IF NOT EXISTS `%s` (\n' % (url,url))
atributes = o.properties['attributes'].value
numAtributes = len(atributes)
for i in range(0,numAtributes, 1):
a = atributes[i]
self.f.write ('\t`%s` %s ' % (a[0], a[1]) )
if a[3] == 1 :
self.f.write (' PRIMARY KEY ')
if a[4] == 0 :
self.f.write (' NOT NULL ')
if a[5] == 1 :
self.f.write (' UNIQUE ')
if i < (numAtributes-1):
self.f.write (',')
self.f.write ('\n')
print a
self.f.write (') ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n')
else:
"""self.f.write ("%s\n" % o.type.name)
k = o.properties.keys()
for i in k:
self.f.write ("%s\n" % i)"""
def end_render (self) :
self.f.write ('-- End MySQL-Dump\n')
self.f.close()
# reference
dia.register_export ("MySQL Dump", "sql", MySqlRenderer())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]