File: mytest.lua

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (98 lines) | stat: -rw-r--r-- 2,390 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

-- list registered modules to screen
print("List of modules")
lsm()

-- print contents of module to screen
print("Showing module mysql")
showm("mysql")


-- connection information for MySQL
conn= {username='root',password='a',hostname='localhost'}

-- setup the parameter to be passed. the parameter of functions are dictionaries that
-- contain function specific items. getSchemaList only needs connection_info
arg= {connect_info=conn}

-- call the function from the module mysql
sl= mysql:getSchemaList(arg)

-- sl= mysql:getSchemaList::({connect_info={username='root',password='root',hostname='localhost'}})

-- print the result, which is also a dictionary. including when an error happens
print("Schemas in mysql server:")
show(sl)

-- setup parameter again.
arg= {connect_info=conn, catalog='def', schema='mysql'}

-- call function
assets= mysql:getSchemaAssets(arg)

-- save the result to a file
save(assets, "assets.xml")

-- load the content of the file back
tmp= load("assets.xml")

-- save again, so we can compare to see if everything is ok
save(tmp, "assets2.xml")

-- convert the GRT_VALUE to a lua table
tbl= unwrap(assets)

-- set some entries from the returned assets in the root object
setobj("/tables", getobj(assets, "/tables"))
setobj("/views", getobj(assets, "/views"))


-- save state
save(getobj("/"), "root.xml")


-- print some stuf
print("Definition of Column User is:")
show(getobj("/tables/user/columns/User"))
print("Definition of Column Host is:")
show(getobj("/tables/user/columns/Host"))



-- some stuff to make navigation easier..

-- "enter" the tables object
cd("/tables")
-- list contents
print("Contents of", pwd())
ls()
-- "enter" the user table's column list. could also be cd("/tables/user/columns")
cd("user/columns")
-- show contents
print("Contents of", pwd())
ls()
-- show value of one 
print("Follows contents of User")
show(getobj("User"))

-- register structs in file
stload("structs_base.xml")

stload("structs_db_base.xml")

-- assign a struct to a dict
usercol= getobj("User")

stset(usercol, "MyxColumn")

print("Assigned struct",stget(usercol),"to object User")
print("Validating...")
if stvalidate(usercol, stget(usercol), 0) ~= 0 then
	print("Validated OK")
else
	print("Validation Error")
end

-- same as above
stvalidate(usercol, 0)