Skip to content

Commit

Permalink
paso algunas def de postgresql a mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel-J committed Nov 12, 2017
1 parent d8f6b5c commit 983fdd3
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 3 deletions.
119 changes: 116 additions & 3 deletions pineboolib/plugins/sql/FLMYSQL_INNODB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
from PyQt5.QtCore import QTime
from pineboolib.flcontrols import ProjectClass
from pineboolib import decorators
from pineboolib.dbschema.schemaupdater import text2bool
from pineboolib.fllegacy.FLUtil import FLUtil
Expand Down Expand Up @@ -105,8 +104,10 @@ def hasFeature(self, value):
return True
else:
return False



def canOverPartition(self):
return True

def nextSerialVal(self, table, field):
q = FLSqlQuery()
q.setSelect(u"nextval('" + table + "_" + field + "_seq')")
Expand Down Expand Up @@ -205,6 +206,19 @@ def setType(self, type_, leng = None):
else:
return "::%s" % type_

def refreshQuery(self, curname, fields, table, where, cursor, conn):
sql = "DECLARE %s NO SCROLL CURSOR WITH HOLD FOR SELECT %s FROM %s WHERE %s " % (curname , fields , table, where)
try:
cursor.execute(sql)
except Exception:
qWarning("CursorTableModel.Refresh\n %s" % traceback.format_exc())

def refreshFetch(self, number, curname, table, cursor, fields, where_filter):
try:
cursor.execute("FETCH %d FROM %s" % (number, curname))
except Exception:
qWarning("PSQLDriver.refreshFetch\n %s" % traceback.format_exc())

def useThreads(self):
return True

Expand All @@ -226,7 +240,106 @@ def existsTable(self, name):

del t
return ok

def sqlCreateTable(self, tmd):
util = FLUtil()
if not tmd:
return None

primaryKey = None
sql = "CREATE TABLE %s (" % tmd.name()
seq = None

fieldList = tmd.fieldList()

unlocks = 0
for field in fieldList:
if field.type() == "unlock":
unlocks = unlocks + 1

if unlocks > 1:
qWarning(u"FLManager : No se ha podido crear la tabla " + tmd.name())
qWarning(u"FLManager : Hay mas de un campo tipo unlock. Solo puede haber uno.")
return None

i = 1
for field in fieldList:
sql = sql + field.name()
if field.type() == "int":
sql = sql + " INT2"
elif field.type() == "uint":
sql = sql + " INT4"
elif field.type() in ("bool","unlock"):
sql = sql + " BOOLEAN"
elif field.type() == "double":
sql = sql + " FLOAT8"
elif field.type() == "time":
sql = sql + " TIME"
elif field.type() == "date":
sql = sql + " DATE"
elif field.type() == "pixmap":
sql = sql + " TEXT"
elif field.type() == "string":
sql = sql + " VARCHAR"
elif field.type() == "stringlist":
sql = sql + " TEXT"
elif field.type() == "bytearray":
sql = sql + " BYTEA"
elif field.type() == "serial":
seq = "%s_%s_seq" % (tmd.name(), field.name())
q = FLSqlQuery()
q.setForwardOnly(True)
q.exec_("SELECT relname FROM pg_class WHERE relname='%s'" % seq)
if not q.next():
q.exec_("CREATE SEQUENCE %s" % seq)

sql = sql + " INT4 DEFAULT NEXTVAL('%s')" % seq
del q

longitud = field.length()
if longitud > 0:
sql = sql + "(%s)" % longitud

if field.isPrimaryKey():
if primaryKey == None:
sql = sql + " PRIMARY KEY"
else:
qWarning(QApplication.tr("FLManager : Tabla-> ") + tmd.name() +
QApplication.tr(" . Se ha intentado poner una segunda clave primaria para el campo ") +
field.name() + QApplication.tr(" , pero el campo ") + primaryKey +
QApplication.tr(" ya es clave primaria. Sólo puede existir una clave primaria en FLTableMetaData, use FLCompoundKey para crear claves compuestas."))
return None
else:
if field.isUnique():
sql = sql + " UNIQUE"
if not field.allowNull():
sql = sql + " NOT NULL"
else:
sql = sql + " NULL"

if not i == len(fieldList):
sql = sql + ","
i = i + 1

sql = sql + ")"

return sql

def mismatchedTable(self, table1, tmd_or_table2, db_):
if isinstance(tmd_or_table2, str):
mtd = db_.manager().metadata(tmd_or_table2, True)
if not mtd:
return False

return False





else:
return self.mismatchedTable(table1, tmd_or_table2.name(), db_)




99 changes: 99 additions & 0 deletions pineboolib/plugins/sql/FLMYSQL_MyISAM.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,105 @@ def existsTable(self, name):

del t
return ok

def sqlCreateTable(self, tmd):
util = FLUtil()
if not tmd:
return None

primaryKey = None
sql = "CREATE TABLE %s (" % tmd.name()
seq = None

fieldList = tmd.fieldList()

unlocks = 0
for field in fieldList:
if field.type() == "unlock":
unlocks = unlocks + 1

if unlocks > 1:
qWarning(u"FLManager : No se ha podido crear la tabla " + tmd.name())
qWarning(u"FLManager : Hay mas de un campo tipo unlock. Solo puede haber uno.")
return None

i = 1
for field in fieldList:
sql = sql + field.name()
if field.type() == "int":
sql = sql + " INT2"
elif field.type() == "uint":
sql = sql + " INT4"
elif field.type() in ("bool","unlock"):
sql = sql + " BOOLEAN"
elif field.type() == "double":
sql = sql + " FLOAT8"
elif field.type() == "time":
sql = sql + " TIME"
elif field.type() == "date":
sql = sql + " DATE"
elif field.type() == "pixmap":
sql = sql + " TEXT"
elif field.type() == "string":
sql = sql + " VARCHAR"
elif field.type() == "stringlist":
sql = sql + " TEXT"
elif field.type() == "bytearray":
sql = sql + " BYTEA"
elif field.type() == "serial":
seq = "%s_%s_seq" % (tmd.name(), field.name())
q = FLSqlQuery()
q.setForwardOnly(True)
q.exec_("SELECT relname FROM pg_class WHERE relname='%s'" % seq)
if not q.next():
q.exec_("CREATE SEQUENCE %s" % seq)

sql = sql + " INT4 DEFAULT NEXTVAL('%s')" % seq
del q

longitud = field.length()
if longitud > 0:
sql = sql + "(%s)" % longitud

if field.isPrimaryKey():
if primaryKey == None:
sql = sql + " PRIMARY KEY"
else:
qWarning(QApplication.tr("FLManager : Tabla-> ") + tmd.name() +
QApplication.tr(" . Se ha intentado poner una segunda clave primaria para el campo ") +
field.name() + QApplication.tr(" , pero el campo ") + primaryKey +
QApplication.tr(" ya es clave primaria. Sólo puede existir una clave primaria en FLTableMetaData, use FLCompoundKey para crear claves compuestas."))
return None
else:
if field.isUnique():
sql = sql + " UNIQUE"
if not field.allowNull():
sql = sql + " NOT NULL"
else:
sql = sql + " NULL"

if not i == len(fieldList):
sql = sql + ","
i = i + 1

sql = sql + ")"

return sql

def mismatchedTable(self, table1, tmd_or_table2, db_):
if isinstance(tmd_or_table2, str):
mtd = db_.manager().metadata(tmd_or_table2, True)
if not mtd:
return False

return False





else:
return self.mismatchedTable(table1, tmd_or_table2.name(), db_)



Expand Down

0 comments on commit 983fdd3

Please sign in to comment.