DBI.lua

changeset 36
942bfe1843bc
parent 22
fd78e9cdc6e9
equal deleted inserted replaced
35:72946c7c68da 36:942bfe1843bc
26 end 26 end
27 end 27 end
28 28
29 -- no drivers available 29 -- no drivers available
30 if table.maxn(available) < 1 then 30 if table.maxn(available) < 1 then
31 return '(None)' 31 available = {'(None)'}
32 end 32 end
33 33
34 return table.concat(available, ',') 34 return available
35 end 35 end
36 36
37 -- High level DB connection function 37 -- High level DB connection function
38 -- This should be used rather than DBD.{Driver}.New 38 -- This should be used rather than DBD.{Driver}.New
39 function Connect(driver, ...) 39 function Connect(driver, ...)
40 local modulefile = name_to_module[driver] 40 local modulefile = name_to_module[driver]
41 41
42 if not modulefile then 42 if not modulefile then
43 error(string.format("Driver '%s' not found. Available drivers are: %s", driver, available_drivers())) 43 local available = table.concat(available_drivers(), ',')
44 error(string.format("Driver '%s' not found. Available drivers are: %s", driver, available))
44 end 45 end
45 46
46 local m, err = pcall(require, modulefile) 47 local m, err = pcall(require, modulefile)
47 48
48 if not m then 49 if not m then
49 -- cannot load the module, we cannot continue 50 -- cannot load the module, we cannot continue
50 error(string.format('Cannot load driver %s. Available drivers are: %s', driver, available_drivers())) 51 local available = table.concat(available_drivers(), ',')
52 error(string.format('Cannot load driver %s. Available drivers are: %s', driver, available))
51 end 53 end
52 54
53 local class_str = string.format('DBD.%s.Connection', driver) 55 local class_str = string.format('DBD.%s.Connection', driver)
54 56
55 local connection_class = package.loaded[class_str] 57 local connection_class = package.loaded[class_str]
73 return false, err 75 return false, err
74 end 76 end
75 77
76 return sth:affected() 78 return sth:affected()
77 end 79 end
80
81 -- Lit drivers available on this system
82 function Drivers()
83 return available_drivers()
84 end

mercurial