Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
curry
curry-tools
Commits
e91c7ea9
Commit
e91c7ea9
authored
Apr 03, 2017
by
Michael Hanus
Browse files
ertools are now downloaded by CPM
parent
9fc4ebc5
Changes
21
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
e91c7ea9
...
...
@@ -24,7 +24,6 @@ currycheck/CurryCheck
currydoc/CurryDoc
currytest/CurryTest
cusage/CheckUsage
ertools/ERD2CDBI
ertools/ERD2Curry
importcalls/ImportCalls
optimize/BindingOpt
...
...
currypp/IntegratedCode/ExamplesSQL/UniERD.curry
0 → 100644
View file @
e91c7ea9
-- ERD specification for university lectures.
import Database.ERD
uniERD :: ERD
uniERD =
ERD "Uni"
[Entity "Student"
[Attribute "Name" (StringDom Nothing) NoKey False,
Attribute "Firstname" (StringDom Nothing) NoKey False,
Attribute "MatNum" (IntDom Nothing) Unique False,
Attribute "Email" (StringDom Nothing) Unique False,
Attribute "Age" (IntDom Nothing) NoKey True],
Entity "Lecture"
[Attribute "Title" (StringDom Nothing) NoKey False,
Attribute "Topic" (StringDom Nothing) NoKey True],
Entity "Lecturer"
[Attribute "Name" (StringDom Nothing) NoKey False,
Attribute "Firstname" (StringDom Nothing) NoKey False],
Entity "Place"
[Attribute "Street" (StringDom Nothing) NoKey False,
Attribute "StrNr" (IntDom Nothing) NoKey False,
Attribute "RoomNr" (IntDom Nothing) NoKey False],
Entity "Time"
[Attribute "Time" (DateDom Nothing) Unique False],
Entity "Exam"
[Attribute "GradeAverage" (FloatDom Nothing) NoKey True],
Entity "Result"
[Attribute "Attempt" (IntDom Nothing) NoKey False,
Attribute "Grade" (FloatDom Nothing) NoKey True,
Attribute "Points" (IntDom Nothing) NoKey True]]
[Relationship "Teaching"
[REnd "Lecturer" "taught_by" (Exactly 1),
REnd "Lecture" "teaches" (Between 0 Infinite)],
Relationship "Participation"
[REnd "Student" "participated_by" (Between 0 Infinite),
REnd "Lecture" "participates" (Between 0 Infinite)],
Relationship "Taking"
[REnd "Result" "has_a" (Between 0 Infinite),
REnd "Student" "belongs_to" (Exactly 1)],
Relationship "Resulting"
[REnd "Exam" "result_of" (Exactly 1),
REnd "Result" "results_in" (Between 0 Infinite)],
Relationship "Belonging"
[REnd "Exam" "has_a" (Between 0 Infinite),
REnd "Lecture" "belongs_to" (Exactly 1)],
Relationship "ExamDate"
[REnd "Exam" "taking_place" (Between 0 Infinite),
REnd "Time" "at" (Exactly 1)],
Relationship "ExamPlace"
[REnd "Exam" "taking_place" (Between 0 Infinite),
REnd "Place" "in" (Exactly 1)]]
\ No newline at end of file
currypp/IntegratedCode/ExamplesSQL/test.sh
View file @
e91c7ea9
...
...
@@ -17,7 +17,7 @@ export PATH
cleandir
()
{
$CURRYBIN
/cleancurry
/bin/rm
-f
$LOGFILE
*
_PUBLIC.curry TEST
*
.curry
/bin/rm
-f
Uni_ERDT.term Uni_SQLCode.info Uni_CDBI.curry Uni.db
/bin/rm
-f
Uni.erdterm
Uni_ERDT.term Uni_SQLCode.info Uni_CDBI.curry Uni.db
$CURRYBIN
/cleancurry
}
...
...
@@ -25,7 +25,7 @@ cleandir () {
exectests
()
{
cleandir
# compile model:
$CURRYBIN
/curry erd2c
dbi Uni_ERD.term
`
pwd
`
/Uni.db
$CURRYBIN
/curry erd2c
urry
--db
`
pwd
`
/Uni.db
--cdbi
UniERD.curry
# fill database:
$CURRYBIN
/curry
$REPL_OPTS
:l CreateData :eval createTestData :q
# run query tests:
...
...
download_tools.sh
View file @
e91c7ea9
...
...
@@ -4,6 +4,25 @@
#
# Note that the execution of this script requires an already installed 'cpm'!
echo
"Updating 'ertools'..."
mv
ertools/Makefile Makefile.ertools
# keep old Makefile
rm
-rf
ertools
cpm checkout ertools
cd
ertools
rm
-rf
.cpm .git
*
# Generate package configuration file:
ERTCONFIG
=
src/ERToolsPackageConfig.curry
echo
"module ERToolsPackageConfig where"
>
$ERTCONFIG
echo
"import Distribution(installDir)"
>>
$ERTCONFIG
echo
"import FilePath(combine)"
>>
$ERTCONFIG
echo
"packageVersion :: String"
>>
$ERTCONFIG
echo
"packageVersion =
\"
1.0.0
\"
"
>>
$ERTCONFIG
echo
"packagePath :: String"
>>
$ERTCONFIG
echo
"packagePath = installDir ++ combine
\"
currytools
\"
\"
ertools
\"
"
>>
$ERTCONFIG
cd
..
mv
Makefile.ertools ertools/Makefile
echo
"'ertools' updated from package repository."
echo
"Updating 'optimize'..."
mv
optimize/Makefile Makefile.optimize
# keep old Makefile
rm
-rf
optimize
...
...
ertools/KeyDatabase.curry.sqlite
deleted
100644 → 0
View file @
9fc4ebc5
This diff is collapsed.
Click to expand it.
ertools/Makefile
View file @
e91c7ea9
#****************************************************************************
# The ERD2C
DBI
tool transforms an ERD term into datatypes for CDBI.
# The ERD2C
urry
tool transforms an ERD term into datatypes for CDBI.
# It also creates an information file for the currypp SQL-Parser.
# If the tool is invoked with the option -db, it creates a
# If the tool is invoked with the option
-
-db, it creates a
# corresponding sqlite database.
#
#****************************************************************************
# installation binaries
ERD2CURRY
=
$(BINDIR)
/
$(CURRYSYSTEM)
-erd2curry
ERD2CDBI
=
$(BINDIR)
/
$(CURRYSYSTEM)
-erd2cdbi
# The tool name of the application:
TOOL
=
$(BINDIR)
/
$(CURRYSYSTEM)
-erd2curry
# Some modules required by the erd2curry tool:
DEPSERD2CURRY
=
ERD2Curry.curry CodeGeneration.curry Transformation.curry
\
XML2ERD.curry ERD2Graph.curry
\
$(ROOT)
/lib/Database/ERD
*
.curry
$(LIBDIR)
/AbstractCurry/
*
.curry
# The load path of the application:
LOADPATH
=
src
# Some modules required by the erd2cdbi tool:
DEPSERD2CDBI
=
ERD2CDBI.curry
$(ROOT)
/lib/Database/ERD
*
.curry
\
$(ROOT)
/lib/Database/CDBI/
*
.curry
# Some modules required by the erd2curry tool:
DEP
=
src/
*
.curry
\
$(ROOT)
/lib/Database/ERD
*
.curry
$(ROOT)
/lib/Database/CDBI/
*
.curry
\
$(LIBDIR)
/AbstractCurry/
*
.curry
.PHONY
:
all compile install clean uninstall
all
:
install
compile
:
$(MAKE)
ERD2Curry
$(MAKE)
ERD2CDBI
compile
:
ERD2Curry
install
:
compile
rm
-f
$(ERD2CURRY)
$(ERD2CDBI)
$(BINDIR)
/erd2curry
$(BINDIR)
/erd2cdbi
cd
$(BINDIR)
&&
ln
-s
../currytools/ertools/ERD2Curry
$(
notdir
$(ERD2CURRY)
)
cd
$(BINDIR)
&&
ln
-s
../currytools/ertools/ERD2CDBI
$(
notdir
$(ERD2CDBI)
)
rm
-f
$(TOOL)
cd
$(BINDIR)
&&
ln
-s
../currytools/ertools/ERD2Curry
$(
notdir
$(TOOL)
)
clean
:
$(CLEANCURRY)
rm
-f
erd2curry ERD2CDBI
cd
src
&&
$(CLEANCURRY)
uninstall
:
clean
rm
-f
$(ERD2CURRY)
$(ERD2CDBI)
ERD2Curry
:
$(DEPSERD2CURRY)
$(REPL)
$(REPL_OPTS)
:load ERD2Curry :save :quit
rm
-f
ERD2Curry
$(TOOL)
ERD2C
DBI
:
$(DEPS
ERD2CDBI
)
$(REPL)
$(REPL_OPTS)
:load ERD2C
DBI
:save :quit
ERD2C
urry
:
$(DEPS)
$(REPL)
$(REPL_OPTS)
:set path
$(LOADPATH)
:load ERD2C
urry
:save :quit
ertools/README
View file @
e91c7ea9
...
...
@@ -11,9 +11,9 @@ ERD2CDBI compiler
This tool transforms an ERD term into datatypes used in the
Database.CDBI. libraries. It also creates an information file
for the currypp SQL-Parser.
If the tool is invoked with the option -db, it creates a
corresponding
sqlite d
atabase.
for the currypp SQL-Parser.
This compiler is invoked by
erd2curry --db <
sqlite
3
d
b file> --cdbi <Curry program with ERD>
----------------------------------------------------------------------
...
...
@@ -70,11 +70,12 @@ erd2curry -v mymodel.erdterm
Examples:
---------
This directory contains two examples for ERD term files:
The directory `examples` contains two examples for the specification
of ERD models:
* `Blog
.erdterm
`: a simple ERD model for a blog with entries, comments,
* `Blog
ERD.curry
`: a simple ERD model for a blog with entries, comments,
and tags.
* `Uni
.erdterm
`: an ERD model for university lectures as
* `Uni
ERD.curry
`: an ERD model for university lectures as
presented in the original paper cited above.
---
...
...
ertools/
D
ocs/README.txt
→
ertools/
d
ocs/README.txt
View file @
e91c7ea9
File moved
ertools/
D
ocs/manual.tex
→
ertools/
d
ocs/manual.tex
View file @
e91c7ea9
File moved
ertools/BlogERD.curry
→
ertools/
examples/
BlogERD.curry
View file @
e91c7ea9
File moved
ertools/ERDGeneric.curry
→
ertools/
examples/
ERDGeneric.curry
View file @
e91c7ea9
...
...
@@ -5,7 +5,7 @@
module ERDGeneric where
import KeyDatabase
import KeyDatabase
SQLite
import List
import ReadShowTerm
import Read
...
...
ertools/UniERD.curry
→
ertools/
examples/
UniERD.curry
View file @
e91c7ea9
File moved
ertools/package.json
0 → 100644
View file @
e91c7ea9
{
"name"
:
"ertools"
,
"version"
:
"1.0.0"
,
"author"
:
"Michael Hanus <mh@informatik.uni-kiel.de>"
,
"synopsis"
:
"Tools for dealing with database applications specified by entity-relationship diagrams"
,
"category"
:
[
"Database"
],
"dependencies"
:
{
},
"configModule"
:
"ERToolsPackageConfig"
,
"executable"
:
{
"name"
:
"erd2curry"
,
"main"
:
"ERD2Curry"
},
"source"
:
{
"git"
:
"https://git.ps.informatik.uni-kiel.de/curry-packages/ertools.git"
,
"tag"
:
"$version"
}
}
ertools/CodeGeneration.curry
→
ertools/
src/
CodeGeneration.curry
View file @
e91c7ea9
...
...
@@ -6,6 +6,8 @@
--- @version February 2015
------------------------------------------------------------------------------
{-# OPTIONS_CYMAKE -Wno-incomplete-patterns #-}
module CodeGeneration(Option,Storage(..),ConsistencyTest(..),
isSQLite,erd2code) where
...
...
@@ -31,7 +33,7 @@ isSQLite (storage,_) =
-- The name of the KeyDatabase module:
keyDatabaseMod :: String
keyDatabaseMod = "KeyDatabase"
keyDatabaseMod = "KeyDatabase
SQLite
"
erd2code :: Option -> ERD -> CurryProg
erd2code opt@(_, consistencyTest) (ERD n es rs) =
...
...
@@ -71,8 +73,8 @@ generateStorageDefinition (storage, _) n = case storage of
where
dbFileDef path =
cfunc (n,"dbFile") 0 Private stringType
[simpleRule [] (string2ac
(
path
++ "/" ++ n ++ ".db")
)]
[simpleRule [] (string2ac path)]
generatedEntity2DBcode :: Option -> String -> [Relationship] -> Entity
-> [CFuncDecl]
generatedEntity2DBcode (storage, _) name allrels
...
...
@@ -254,7 +256,6 @@ entity2datatype _ ername (Entity name attrs) =
[CType (ername,name) Public [] [CCons (ername,name) Private argTypes],
CTypeSyn (ername,name++"Tuple") Private [] (tupleType (tail argTypes))]
where
arity = length attrs
argTypes = map attrType attrs
-- Create transformation between entity type and tuple representation:
...
...
@@ -599,7 +600,7 @@ entitySpec (s,eName) attrs v =
-- Generate persistent dynamic predicate for an entity using SQLite3 DB
-- of Sebastian Fischer's KeyDatabase module.
predEntrySQLite :: QName -> [Attribute] -> CVisibility -> String -> CFuncDecl
predEntrySQLite (s,eName) attrs v
dbpath
=
predEntrySQLite (s,eName) attrs v
_
=
cmtfunc
("Database predicate representing the relation between keys and "++eName++
" tuple entities.")
...
...
@@ -856,9 +857,6 @@ newEntity (str,eName) attrs ens rels v esAll rsAll =
case c of (Between i (Max j)) -> i>0 && j>i
_ -> False
getExactB (Relationship _ [REnd _ _ _, REnd _ _ (Exactly i)]) = i
getMinB (Relationship _ [REnd _ _ _, REnd _ _ (Between i _)]) = i
duplicate [] [] = []
duplicate (Relationship _ [REnd _ _ _, REnd _ _ (Exactly i)]:exactRs) (p:ps) =
(map ((p++) . show) [1..i]) ++ (duplicate exactRs ps)
...
...
@@ -1312,6 +1310,7 @@ rel2code option name es r =
then rolesR option name r es
else roles name r
isGeneratedR :: Relationship -> Bool
isGeneratedR (Relationship n _) = n == ""
--generierte Beziehung als Teil der Umsetzung einer n:m Beziehung
...
...
@@ -1592,6 +1591,7 @@ hasDefault (DateDom d) = isJust d
hasDefault (UserDefined _ d) = isJust d
-- Get the default value of the attribute domain:
getDefault :: Domain -> CExpr
getDefault (IntDom (Just d)) = CLit (CIntc d)
getDefault (FloatDom (Just d)) = CLit (CFloatc d)
getDefault (StringDom (Just d)) = string2ac d
...
...
ertools/ERD2CDBI.curry
→
ertools/
src/
ERD2CDBI.curry
View file @
e91c7ea9
...
...
@@ -7,7 +7,7 @@
--- `x_SQLCODE.info` that is used when embedded SQL statements are
--- translated by the Curry preprocessor `currypp`.
---
--- @author Mike Tallarek, extensions by Julia Krone
--- @author Mike Tallarek, extensions by Julia Krone
and Michael Hanus
--- @version 0.2
--- ----------------------------------------------------------------------------
...
...
@@ -20,7 +20,7 @@ import AbstractCurry.Build
import Char ( toLower, toUpper )
import Database.ERD
import Database.ERDGoodies
import Directory ( doesFileExist )
import Directory ( doesFileExist
, getAbsolutePath
)
import Distribution ( installDir )
import qualified FilePath as FP ( (</>), combine, splitFileName)
import IO
...
...
@@ -32,45 +32,13 @@ import SetFunctions ( selectValue, set2 )
import System
import Time
-- Takes a x_ERD.term or x_ERDT.term (an ER-Model translated by erd2curry)
-- and the absolute path to the database.
-- Creates a SQLite database (if it does not exist,
-- a .curry program with all datatypes
-- and an .info-file for the CurryPP-SQLParser
main :: IO ()
main = do
args <- getArgs
case args of
[erdfname, dbPath] -> do erdterm <- translateERD2ERDT erdfname
writeCDBI erdfname erdterm dbPath
_ -> showUsageString
showUsageString :: IO ()
showUsageString = do
putStrLn $ unlines
["Usage: curry erd2cdbi <ERD file> <DB path>",
"",
"<ERD file>: name of file containing ERD specification",
"<DB path> : absolute path to database (including name of database)>"]
exitWith 1
-- Translate the ERD file, if it is not a ERDT file, into ERDT format
-- by the use of erd2curry tools, and read ERDT file:
translateERD2ERDT :: String -> IO ERD
translateERD2ERDT erdfname = do
erdterm <- readERDTermFile erdfname
let (dir,file) = FP.splitFileName erdfname
erdtfile = erdName erdterm ++ "_ERDT.term"
if file == erdtfile
then return erdterm
else do system (unwords [installDir FP.</> "bin" FP.</> "curry", "erd2curry",
"-t ",erdfname])
readERDTermFile (FP.combine dir erdtfile)
-- Write all the data so CDBI can be used, create a database
-- when option is set and a .info file
-- Write all the data so CDBI can be used, create a database (if it does
-- not exist) and a .info file/
-- The parameters are the name of the file containing the ERD term,
-- the ER model, and the name of the SQLite3 database.
writeCDBI :: String -> ERD -> String -> IO ()
writeCDBI erdfname (ERD name ents rels) dbPath = do
writeCDBI erdfname (ERD name ents rels) dbname = do
dbPath <- getAbsolutePath dbname
let cdbiMod = name++"_CDBI"
cdbiFile = cdbiMod++".curry"
imports = [ "Time"
...
...
ertools/ERD2Curry.curry
→
ertools/
src/
ERD2Curry.curry
View file @
e91c7ea9
module ERD2Curry where
module ERD2Curry( main, erd2curryWithDBandERD )
where
import AbstractCurry.Files (readCurry)
import AbstractCurry.Select (imports)
...
...
@@ -13,109 +14,142 @@ import System (exitWith, getArgs, system)
import Time
import XML
import XML2ERD
import Transformation
import CodeGeneration
import ERD2CDBI (writeCDBI)
import ERD2Graph
import ERToolsPackageConfig(packagePath, packageVersion)
import Transformation
import XML2ERD
systemBanner :: String
systemBanner =
let bannerText = "ERD->Curry Compiler (Version of 12/01/17)"
let bannerText = "ERD->Curry Compiler (Version " ++ packageVersion ++
" of 09/03/17)"
bannerLine = take (length bannerText) (repeat '-')
in bannerLine ++ "\n" ++ bannerText ++ "\n" ++ bannerLine
data EROptions = EROptions
{ optERProg :: String -- Curry program containing ERD
, optFromXml :: Bool -- read ERD from XML file?
, optVisualize :: Bool -- visualize ERD?
, optStorage :: Storage -- storage of data
, optToERDT :: Bool -- only transform into ERDT term file
, optCDBI :: Bool -- generate Curry for Database.CDBI libraries
}
defaultEROptions :: EROptions
defaultEROptions = EROptions
{ optERProg = ""
, optFromXml = False
, optVisualize = False
, optStorage = SQLite ""
, optToERDT = False
, optCDBI = False
}
--- Main function for saved state. The argument is the directory containing
--- these sources.
main :: IO ()
main = do
putStrLn systemBanner
args <- getArgs
configs <- parseArgs ("",False,SQLite ".",False,False) args
-- the directory containing the sources of this tool:
let erd2currydir = installDir </> "currytools" </> "ertools"
callStart erd2currydir configs
configs <- parseArgs defaultEROptions args
startERD2Curry configs
parseArgs :: (String,Bool,Storage,Bool,Bool) -> [String]
-> IO (Maybe (String,Bool,Storage,Bool,Bool))
parseArgs :: EROptions -> [String] -> IO (Maybe EROptions)
parseArgs _ [] = return Nothing
parseArgs
(file,fromxml,storage,vis,trerdt)
(arg:args) = case arg of
parseArgs
opts
(arg:args) = case arg of
"-h" -> putStrLn helpText >> exitWith 0
"-?" -> putStrLn helpText >> exitWith 0
"--help" -> putStrLn helpText >> exitWith 0
"-x" -> parseArgs (file,True,storage,vis,trerdt) args
"-l" -> parseArgs (file,fromxml,setSQLite storage,vis,trerdt) args
"-f" -> if curryCompiler == "pakcs"
then parseArgs (file,fromxml,setFileDB storage,vis,trerdt) args
else error "Wrong parameter -f: file-based database only available in PAKCS!"
"-d" -> parseArgs (file,fromxml,DB,vis,trerdt) args
"-p" -> if null args then return Nothing else
parseArgs (file,fromxml,setFilePath (head args) storage,vis,trerdt)
(tail args)
"--dbpath" ->
if null args then return Nothing else
parseArgs (file,fromxml,setFilePath (head args) storage,vis,trerdt)
(tail args)
"-t" -> parseArgs (file,fromxml,storage,vis,True) args
"-v" -> parseArgs (file,fromxml,storage,True,trerdt) args
f -> return $ if null args then Just (f,fromxml,storage,vis,trerdt)
"-x" -> parseArgs opts { optFromXml = True } args
"-l" -> parseArgs (setSQLite (optStorage opts)) args
"-d" -> parseArgs opts { optStorage = DB } args
"--db" -> if null args
then return Nothing
else parseArgs (setFilePath (head args) (optStorage opts))
(tail args)
"-t" -> parseArgs opts { optToERDT = True } args
"-v" -> parseArgs opts { optVisualize = True } args
"--cdbi" -> parseArgs opts { optCDBI = True } args
f -> return $ if null args then Just opts { optERProg = f }
else Nothing
where
setFilePath path (Files _) = Files path
setFilePath path (SQLite _) = SQLite path
setFilePath _ DB =
DB
setFilePath path (Files _) =
opts { optStorage =
Files path
}
setFilePath path (SQLite _) =
opts { optStorage =
SQLite path
}
setFilePath _ DB =
opts { optStorage = DB }
setSQLite (Files p) = SQLite p
setSQLite (SQLite p) = SQLite p
setSQLite DB = SQLite "
.
"
setSQLite (Files p) =
opts { optStorage =
SQLite p
}
setSQLite (SQLite p) =
opts { optStorage =
SQLite p
}
setSQLite DB =
opts { optStorage =
SQLite ""
}
setFileDB (Files p) = Files p
setFileDB (SQLite p) = Files p
setFileDB DB = Files "."
storagePath :: Storage -> String
storagePath (Files p) = p
storagePath (SQLite p) = p
storagePath DB = ""
helpText :: String
helpText = unlines
[ "Usage:"
, ""
, "
curry
erd2curry [-l]
[-f]
[-d] [-t] [-x] [-v] [--db
path <dir>
] <prog>"
, " erd2curry [-l] [-d] [-t] [-x] [-v] [--db
<dbfile>] [--cdbi
] <prog>"
, ""
, "Parameters:"
, "-l: generate interface to SQLite3 database (default)"
, "-f: generate interface to file-based database implementation (only in PAKCS)"
, "-d: generate interface to SQL database (experimental)"
, "-x: generate from ERD xmi document instead of ERD Curry program"
, "-t: only transform ERD into ERDT term file"
, "-v: only show visualization of ERD with dotty"
, "--dbpath <dir>: name of the directory where DB files are stored"
, "<prog> : name of Curry program file containing ERD definition"
, "--db <dbfile>: file of the SQLite3 database"
, "--cdbi : generate Curry module for Database.CDBI modules"
, "<prog> : name of Curry program file containing ERD definition"
]
callStart :: String -> Maybe (String,Bool,Storage,Bool,Bool) -> IO ()
callStart _ Nothing = do
--- Runs ERD2Curry with a given database and ERD term file or program.
erd2curryWithDBandERD :: String -> String -> IO ()
erd2curryWithDBandERD dbname erfile =
startERD2Curry
(Just defaultEROptions
{ optStorage = SQLite dbname, optERProg = erfile })
startERD2Curry :: Maybe EROptions -> IO ()
startERD2Curry Nothing = do
putStrLn $ "ERROR: Illegal arguments\n\n" ++ helpText
exitWith 1
callStart erd2currydir (Just (orgfile,fromxml,storage,vis,trerdt)) = do
file <- if ".curry" `isSuffixOf` orgfile
then storeERDFromProgram orgfile
else return orgfile
if vis
then readERDTermFile file >>= viewERD
else start erd2currydir (storage,WithConsistencyTest) fromxml trerdt file "."
startERD2Curry (Just opts) = do
-- the directory containing the sources of this tool:
let erd2currysrcdir = packagePath </> "src"
orgfile = optERProg opts
erdfile <- if ".curry" `isSuffixOf` orgfile ||
".lcurry" `isSuffixOf` orgfile
then storeERDFromProgram orgfile
else return orgfile
if optVisualize opts
then readERDTermFile erdfile >>= viewERD
else start erd2currysrcdir opts erdfile "."
--- Main function to invoke the ERD->Curry translator.
start :: String -> Option
-> Bool -> Bool
-> String -> String -> IO ()
start erd2currydir opt
fromxml trerdt
srcfile path = do
(erdfile,erd) <- if
f
rom
x
ml
start :: String ->
ER
Option
s
-> String -> String -> IO ()
start erd2curry
src
dir opt
s
srcfile path = do
(erdfile,erd) <- if
optF
rom
X
ml
opts
then transformXmlFile srcfile path
else readERDTermFile srcfile >>= \e -> return (srcfile,e)
let transerdfile = addPath path (erdName erd ++ "_ERDT.term")
curryfile = addPath path (erdName erd ++ ".curry")
let erdname = erdName erd
transerdfile = addPath path (erdname ++ "_ERDT.term")
curryfile = addPath path (erdname ++ ".curry")
transerd = transform erd
opt = ( if optStorage opts == SQLite ""
then SQLite (erdname ++ ".db")
else optStorage opts
, WithConsistencyTest )
erdprog = erd2code opt (transform erd)
writeFile transerdfile
("{- ERD specification transformed from "++erdfile++" -}\n\n " ++
showERD 2 transerd ++ "\n")
putStrLn $ "Transformed ERD term written into file '"++transerdfile++"'."
unless trerdt $ do
when (optCDBI opts) $
writeCDBI srcfile transerd (storagePath (fst opt))
unless (optToERDT opts || optCDBI opts) $ do
copyAuxiliaryFiles
moveOldVersion curryfile
curdir <- getCurrentDirectory
...
...
@@ -126,27 +160,23 @@ start erd2currydir opt fromxml trerdt srcfile path = do
prettyCurryProg
(setOnDemandQualification (erdprog:impprogs) defaultOptions)
erdprog
putStrLn $ "Database operations generated into file '"++curryfile
++"'\n"
++
"with " ++ showOption
(erdName erd)
opt ++ ".\n"
putStrLn $ "Database operations generated into file '"
++
curryfile
++
"
'\n
with " ++ showOption opt ++ ".\n"
where
-- Copy auxiliary files ERDGeneric.curry and KeyDatabase.curry to target dir
copyAuxiliaryFiles = do
if isSQLite opt
then copyFile (erd2currydir </> "KeyDatabase.curry.sqlite")
(addPath path "KeyDatabase.curry")
else done
copyFile (erd2currydir </> "ERDGeneric.curry")
copyFile (erd2currysrcdir </> "ERDGeneric.curry")
(addPath path "ERDGeneric.curry")
showOption
_
(Files f,_) = "database files stored in directory '"++f++"'"
showOption
ername
(SQLite
p
,_) =
"SQLite3 database stored in file '"
++p++"/"++ername++".db
'"
showOption
_
(DB,_) = "SQL database interface"
showOption (Files f,_) = "database files stored in directory '"++f++"'"
showOption (SQLite
f
,_) =
"SQLite3 database stored in file '"
++ f ++ "
'"
showOption (DB,_) = "SQL database interface"
--- Adds a path to a file name.
addPath :: String -> String -> String
addPath path fname | path=="." = fname
| otherwise = path
++"/"++
fname
| otherwise = path
</>
fname
--- Moves a file (if it exists) to one with extension ".versYYMMDDhhmmss".
moveOldVersion :: String -> IO ()
...
...
ertools/ERD2Graph.curry
→
ertools/
src/
ERD2Graph.curry
View file @
e91c7ea9
...
...
@@ -2,6 +2,8 @@
--- This module defines an operation to visualize an ERD term with dot.
---------------------------------------------------------------------
{-# OPTIONS_CYMAKE -Wno-incomplete-patterns #-}
module ERD2Graph(viewERD) where
import IO
...
...
@@ -15,6 +17,7 @@ import Distribution(getRcVar)
-- If not, it will be represented as an arc with a label.
-- However, some graph drawing tools have problems to write the
-- labels in a good manner to the arcs.
relationAsNode :: Bool
relationAsNode = True
-- Visualize an ERD term with dot.
...
...
ertools/src/ERDGeneric.curry
0 → 100644
View file @
e91c7ea9
------------------------------------------------------------------------------
--- Generic operations and integrity tests
--- to support the database code generated from ERDs
------------------------------------------------------------------------------
module ERDGeneric where
import KeyDatabaseSQLite
import List
import ReadShowTerm