| 1 |
package.path = package.path .. ";/Users/rszwarc/Developer/Lua/LU/?.lua" |
|---|
| 2 |
package.cpath = package.cpath .. ";/Users/rszwarc/Developer/Lua/LU/Library/Modules/?.so" |
|---|
| 3 |
|
|---|
| 4 |
local LUFile = require( "LUFile" ) |
|---|
| 5 |
local LUList = require( "LUList" ) |
|---|
| 6 |
local LUMap = require( "LUMap" ) |
|---|
| 7 |
local LUObjectReader = require( "LUObjectReader" ) |
|---|
| 8 |
local LUObjectWriter = require( "LUObjectWriter" ) |
|---|
| 9 |
local DB = require( "DB" ) |
|---|
| 10 |
local DBSQLSelect = require( "DBSQLSelect" ) |
|---|
| 11 |
local DBSQLOrdering = require( "DBSQLOrdering" ) |
|---|
| 12 |
local DBSQLOrder = require( "DBSQLOrder" ) |
|---|
| 13 |
local DBSQLStatement = require( "DBSQLStatement" ) |
|---|
| 14 |
|
|---|
| 15 |
local aName = "Vlad'imir" |
|---|
| 16 |
local aCity = "Mosk'va" |
|---|
| 17 |
|
|---|
| 18 |
--[[ |
|---|
| 19 |
local aStatement = function() |
|---|
| 20 |
Select( hr.v_employee ) |
|---|
| 21 |
Where( Eq( name, aName ), Eq( city, aCity ), Lt( id, 10 ), Not( Ne( state, nil ) ) ) |
|---|
| 22 |
Order( By( name ) ) |
|---|
| 23 |
end |
|---|
| 24 |
]]-- |
|---|
| 25 |
|
|---|
| 26 |
--[[ |
|---|
| 27 |
local aStatement = function() |
|---|
| 28 |
Select( information_schema.TABLES, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE ) |
|---|
| 29 |
-- Where( Eq( table_name, "country" ) ) |
|---|
| 30 |
Order( By( table_schema ), By( table_name ) ) |
|---|
| 31 |
end |
|---|
| 32 |
]]-- |
|---|
| 33 |
|
|---|
| 34 |
--[[ |
|---|
| 35 |
local aStatement = function() |
|---|
| 36 |
Select( information_schema.COLUMNS, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE ) |
|---|
| 37 |
Order( By( TABLE_SCHEMA ), By( TABLE_NAME ), By( COLUMN_NAME ) ) |
|---|
| 38 |
end |
|---|
| 39 |
]]-- |
|---|
| 40 |
|
|---|
| 41 |
--[[ |
|---|
| 42 |
local aStatement = function() |
|---|
| 43 |
Select( information_schema.TABLE_CONSTRAINTS, TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_NAME, CONSTRAINT_TYPE ) |
|---|
| 44 |
Order( By( TABLE_SCHEMA ), By( TABLE_NAME ), By( CONSTRAINT_TYPE ) ) |
|---|
| 45 |
end |
|---|
| 46 |
]]-- |
|---|
| 47 |
|
|---|
| 48 |
local aStatement = function() |
|---|
| 49 |
Select( information_schema.KEY_COLUMN_USAGE, TABLE_SCHEMA, TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME ) |
|---|
| 50 |
Where( Eq( TABLE_NAME, CountryLanguage ) ) |
|---|
| 51 |
Order( By( TABLE_SCHEMA ), By( TABLE_NAME ), By( COLUMN_NAME ) ) |
|---|
| 52 |
end |
|---|
| 53 |
|
|---|
| 54 |
--[[ |
|---|
| 55 |
local aStatement = function() |
|---|
| 56 |
Select( information_schema.schemata ) |
|---|
| 57 |
Where( In( name, function() Select( information_schema.KEY_COLUMN_USAGE ) Where( Eq( TABLE_NAME, CountryLanguage ) ) end ) ) |
|---|
| 58 |
end |
|---|
| 59 |
]]-- |
|---|
| 60 |
|
|---|
| 61 |
--[[ |
|---|
| 62 |
local aStatement = function() |
|---|
| 63 |
Select( country ) |
|---|
| 64 |
Order( By( code ) ) |
|---|
| 65 |
end |
|---|
| 66 |
]]-- |
|---|
| 67 |
|
|---|
| 68 |
-- local aStatement = "select * from information_schema.columns order by table_name, column_name" |
|---|
| 69 |
-- local aStatement = DBSQLSelect( "information_schema.columns" ):setOrdering( DBSQLOrdering( LUList( { DBSQLOrder( "table_name" ), DBSQLOrder( "column_name" ) } ) ) ) |
|---|
| 70 |
|
|---|
| 71 |
--[[ |
|---|
| 72 |
local aDB = DB( "mysql://localhost/test" ) |
|---|
| 73 |
|
|---|
| 74 |
for anIndex, aValue in aDB:run( aStatement ) do |
|---|
| 75 |
print( anIndex, aValue ) |
|---|
| 76 |
end |
|---|
| 77 |
|
|---|
| 78 |
aDB:close() |
|---|
| 79 |
]]-- |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
print( DBSQLStatement( aStatement ):evaluate() ) |
|---|
| 83 |
|
|---|
| 84 |
local aStatement = function() |
|---|
| 85 |
Select( people, name, email ) |
|---|
| 86 |
end |
|---|
| 87 |
|
|---|
| 88 |
print( DBSQLStatement( aStatement ):evaluate() ) |
|---|
| 89 |
|
|---|
| 90 |
local aPerson = LUMap( { name = "Jose das Couves", email = "jose@couves.com", id = 1 } ) |
|---|
| 91 |
local anotherPerson = LUMap( { name = "Manoel Joaquim", email = "manoel.joaquim@cafundo.com", id = 2, active = true } ) |
|---|
| 92 |
|
|---|
| 93 |
local aStatement = function() |
|---|
| 94 |
Insert( people, name, email, id, active, date ) |
|---|
| 95 |
Values( aPerson, anotherPerson ) |
|---|
| 96 |
end |
|---|
| 97 |
|
|---|
| 98 |
print( DBSQLStatement( aStatement ):evaluate() ) |
|---|
| 99 |
|
|---|
| 100 |
local aStatement = function() |
|---|
| 101 |
Update( people, name, email, id, active ) |
|---|
| 102 |
Values( aPerson ) |
|---|
| 103 |
Where( Eq( name, aName ) ) |
|---|
| 104 |
end |
|---|
| 105 |
|
|---|
| 106 |
print( DBSQLStatement( aStatement ):evaluate() ) |
|---|
| 107 |
|
|---|
| 108 |
local aStatement = function() |
|---|
| 109 |
Delete( people ) |
|---|
| 110 |
Where( Eq( name, aName ) ) |
|---|
| 111 |
end |
|---|
| 112 |
|
|---|
| 113 |
print( DBSQLStatement( aStatement ):evaluate() ) |
|---|
| 114 |
|
|---|