0% found this document useful (0 votes)
341 views

Stru2mysql 2.prg

Uploaded by

Jhon Thomas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
341 views

Stru2mysql 2.prg

Uploaded by

Jhon Thomas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#DEFINE CR #DEFINE TABB SET SAFETY OFF

CHR(13) CHR(9)

? TIME(), REPLICATE("=", 50) loS2M = CREATEOBJECT("Stru2MySQL") IF VARTYPE(loS2M) = "O" loS2M.ScriptAll() ENDIF ? TIME(), REPLICATE("-", 50) ********************************************************************** ********************************************************************** ********************************************************************** DEFINE CLASS Stru2MySQL AS Custom cEngine = [ ENGINE=InnoDB] ou want to use transactions in MySQL! Engine to blank for use of MyISAM engine. *!************************************************ *!* Program: ScriptAll *!* Author: CULLY Technologies, LLC *!* Date: 06/18/07 01:55:33 PM *!* Copyright: *!* Description: *!* Revision Information: FUNCTION ScriptAll LOCAL llRetVal, lnX, lnOrigArea llRetVal = .T. lnOrigArea = SELECT() lcFullScript = FOR lnX = 1 TO SELECT IF NOT [] 100 (lnX) EMPTY(ALIAS()) lcOneScript = THIS.ScriptOne() IF NOT EMPTY(lcOneScript) lcFullScript = lcFullScript + lcOneScript + CR ENDIF && Set to [ ENGINE=InnoDB] if y && Set c

ENDIF ENDFOR IF NOT EMPTY(lcFullScript) STRTOFILE(lcFullScript, 'Make_All.sql') ? TIME(), [Make_All.sql] ENDIF SELECT (lnOrigArea) RETURN llRetVal ENDFUNC *!************************************************ *!* Program: ScriptOne *!* Author: Ed Leafe *!* Date: Unknown *!* Copyright:

*!* Description: *!* Revision Information: FUNCTION ScriptOne(tcAlias AS String) LOCAL lcOut, lnF, lcField, lcType, lnLen, lnDec, ln8Len, lcFile, lnCnt, aa[1] IF NOT EMPTY(tcAlias) SELECT (tcAlias) ENDIF lcOut = "" lnF = AFIELDS(aa) FOR lnCnt = 1 TO lnF lcField = LOWER(aa[lnCnt, 1]) lcType = aa[lnCnt, 2] lnLen = aa[lnCnt, 3] lnDec = aa[lnCnt, 4] ln8Len = THIS.next8(lnLen) lcOut = lcOut + TABB DO CASE CASE lcType == "C" lcOut = lcOut + lcField + [ varchar (] + TRANSFO RM(ln8Len) + [) not null default '', ] CASE lcType == "I" DO CASE CASE lnLen < 4 lcOut = lcOut + lcField + [ tiny int unsigned not null default 0, ] CASE lnLen < 8 lcOut = lcOut + lcField + [ int unsigned not null default 0, ] OTHERWISE lcOut = lcOut + lcField + [ medi umint unsigned not null default 0, ] ENDCASE CASE INLIST(lcType, "N", "Y") IF lnDec = 0 DO CASE CASE lnLen < 4 lcOut = lcOut + lcField + [ tinyint unsigned not null default 0, ] CASE lnLen < 8 lcOut = lcOut + lcField + [ int unsigned not null default 0, ] OTHERWISE lcOut = lcOut + lcField + [ mediumint unsigned not null default 0, ] ENDCASE ELSE lcOut = lcOut + lcField + [ decimal (] + TRANSFORM(ln8Len) + [, ] + TRANSFORM(lnDec) + [) not null default 0, ] ENDIF CASE lcType == "T" lcOut = lcOut + lcField + [ datetime not null, ]

CASE lcType == "D" lcOut = lcOut + lcField + [ date not null, ] CASE lcType == "M" lcOut = lcOut + lcField + [ text not null defaul t '', ] CASE lcType == "L" lcOut = lcOut + lcField + [ tinyint unsigned not null default '0', ] ENDCASE IF lnCnt = lnF * Last entry; strip the comma lcOut = SUBSTR(lcOut, 1, LEN(lcOut)-2) ELSE lcOut = lcOut + CR ENDIF ENDFOR lcTableName = LOWER(ALIAS()) lcFile = [make_] + lcTableName + [.sql] lcOut = [DROP TABLE IF EXISTS ]+lcTableName+[;] + CR + ; [create table ] + lcTableName + [ (] + CR + lcOut + CR + [)] + T HIS.cEngine + [;] STRTOFILE(lcOut, lcFile) && MODIFY FILE (lcFile) NOWAIT ? TIME(), lcFile RETURN lcOut ENDFUNC FUNCTION next8(tnVal) LOCAL lnExtra lnExtra = tnVal % 8 IF lnExtra > 0 lnExtra = 8 - lnExtra ENDIF RETURN tnVal + lnExtra ENDFUNC ENDDEFINE

You might also like