lafcadio 0.4.3 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/lafcadio_schema +28 -0
- data/lib/lafcadio.rb +3 -4
- data/lib/lafcadio.rb~ +3 -4
- data/lib/lafcadio/TestSuite.rb +2 -0
- data/lib/lafcadio/TestSuite.rb~ +16 -0
- data/lib/lafcadio/dateTime.rb +93 -2
- data/lib/lafcadio/{dateTime/Month.rb → dateTime.rb~} +33 -33
- data/lib/lafcadio/depend.rb +3 -0
- data/lib/lafcadio/domain.rb +574 -70
- data/lib/lafcadio/domain.rb~ +570 -70
- data/lib/lafcadio/mock.rb +92 -2
- data/lib/lafcadio/mock.rb~ +93 -0
- data/lib/lafcadio/objectField.rb +614 -3
- data/lib/lafcadio/objectField.rb~ +618 -0
- data/lib/lafcadio/objectStore.rb +662 -19
- data/lib/lafcadio/objectStore.rb~ +746 -0
- data/lib/lafcadio/query.rb +415 -31
- data/lib/lafcadio/query.rb~ +572 -0
- data/lib/lafcadio/schema.rb +57 -2
- data/lib/lafcadio/test.rb +17 -2
- data/lib/lafcadio/{test/LafcadioTestCase.rb → test.rb~} +5 -5
- data/lib/lafcadio/test/testconfig.dat +1 -1
- data/lib/lafcadio/util.rb +337 -20
- metadata +16 -77
- data/lib/lafcadio/domain/DomainObject.rb +0 -375
- data/lib/lafcadio/domain/DomainObject.rb~ +0 -371
- data/lib/lafcadio/domain/MapObject.rb +0 -22
- data/lib/lafcadio/domain/ObjectType.rb +0 -80
- data/lib/lafcadio/includer.rb +0 -18
- data/lib/lafcadio/mock/MockDbBridge.rb +0 -78
- data/lib/lafcadio/mock/MockDbBridge.rb~ +0 -74
- data/lib/lafcadio/mock/MockObjectStore.rb +0 -20
- data/lib/lafcadio/objectField/AutoIncrementField.rb +0 -25
- data/lib/lafcadio/objectField/BooleanField.rb +0 -83
- data/lib/lafcadio/objectField/DateField.rb +0 -33
- data/lib/lafcadio/objectField/DateTimeField.rb +0 -25
- data/lib/lafcadio/objectField/DecimalField.rb +0 -41
- data/lib/lafcadio/objectField/EmailField.rb +0 -28
- data/lib/lafcadio/objectField/EnumField.rb +0 -62
- data/lib/lafcadio/objectField/FieldValueError.rb +0 -4
- data/lib/lafcadio/objectField/IntegerField.rb +0 -15
- data/lib/lafcadio/objectField/LinkField.rb +0 -92
- data/lib/lafcadio/objectField/LinkField.rb~ +0 -86
- data/lib/lafcadio/objectField/MoneyField.rb +0 -13
- data/lib/lafcadio/objectField/MonthField.rb +0 -16
- data/lib/lafcadio/objectField/ObjectField.rb +0 -142
- data/lib/lafcadio/objectField/PasswordField.rb +0 -29
- data/lib/lafcadio/objectField/StateField.rb +0 -13
- data/lib/lafcadio/objectField/SubsetLinkField.rb +0 -25
- data/lib/lafcadio/objectField/TextField.rb +0 -23
- data/lib/lafcadio/objectField/TextListField.rb +0 -21
- data/lib/lafcadio/objectField/TimeStampField.rb +0 -15
- data/lib/lafcadio/objectStore/Cache.rb +0 -81
- data/lib/lafcadio/objectStore/Committer.rb +0 -65
- data/lib/lafcadio/objectStore/CouldntMatchObjectTypeError.rb +0 -4
- data/lib/lafcadio/objectStore/DbBridge.rb +0 -140
- data/lib/lafcadio/objectStore/DbBridge.rb~ +0 -140
- data/lib/lafcadio/objectStore/DomainComparable.rb +0 -25
- data/lib/lafcadio/objectStore/DomainObjectInitError.rb +0 -9
- data/lib/lafcadio/objectStore/DomainObjectNotFoundError.rb +0 -4
- data/lib/lafcadio/objectStore/DomainObjectProxy.rb +0 -62
- data/lib/lafcadio/objectStore/DomainObjectSqlMaker.rb +0 -74
- data/lib/lafcadio/objectStore/ObjectStore.rb +0 -207
- data/lib/lafcadio/objectStore/ObjectStore.rb~ +0 -207
- data/lib/lafcadio/objectStore/SqlValueConverter.rb +0 -30
- data/lib/lafcadio/objectStore/SqlValueConverter.rb~ +0 -30
- data/lib/lafcadio/query/Compare.rb +0 -55
- data/lib/lafcadio/query/CompoundCondition.rb +0 -39
- data/lib/lafcadio/query/Condition.rb +0 -66
- data/lib/lafcadio/query/Condition.rb~ +0 -66
- data/lib/lafcadio/query/Equals.rb +0 -45
- data/lib/lafcadio/query/In.rb +0 -20
- data/lib/lafcadio/query/Like.rb +0 -48
- data/lib/lafcadio/query/Link.rb +0 -20
- data/lib/lafcadio/query/Max.rb +0 -32
- data/lib/lafcadio/query/Max.rb~ +0 -25
- data/lib/lafcadio/query/Not.rb +0 -21
- data/lib/lafcadio/query/Query.rb +0 -92
- data/lib/lafcadio/schema/CreateTableStatement.rb +0 -61
- data/lib/lafcadio/schema/CreateTableStatement.rb~ +0 -59
- data/lib/lafcadio/util/Context.rb +0 -61
- data/lib/lafcadio/util/ContextualService.rb +0 -33
- data/lib/lafcadio/util/English.rb +0 -117
- data/lib/lafcadio/util/HashOfArrays.rb +0 -48
- data/lib/lafcadio/util/LafcadioConfig.rb +0 -25
- data/lib/lafcadio/util/QueueHash.rb +0 -67
- data/lib/lafcadio/util/UsStates.rb +0 -29
- data/lib/lafcadio/xml.rb +0 -2
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'lafcadio/objectField/ObjectField'
|
2
|
-
|
3
|
-
module Lafcadio
|
4
|
-
# A TextField is expected to contain a string value.
|
5
|
-
class TextField < ObjectField
|
6
|
-
attr_accessor :large, :size
|
7
|
-
|
8
|
-
def initialize(objectType, name, englishName = nil)
|
9
|
-
super objectType, name, englishName
|
10
|
-
@large = false
|
11
|
-
end
|
12
|
-
|
13
|
-
def valueForSQL(value) #:nodoc:
|
14
|
-
if value
|
15
|
-
value = value.gsub(/(\\?')/) { |m| m.length == 1 ? "''" : m }
|
16
|
-
value = value.gsub(/\\/) { '\\\\' }
|
17
|
-
"'#{value}'"
|
18
|
-
else
|
19
|
-
"null"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'lafcadio/objectField/ObjectField'
|
2
|
-
|
3
|
-
module Lafcadio
|
4
|
-
# TextListField maps to any String SQL field that tries to represent a
|
5
|
-
# quick-and-dirty list with a comma-separated string. It returns an Array.
|
6
|
-
# For example, a SQL field with the value "john,bill,dave", then the Ruby
|
7
|
-
# field will have the value <tt>[ "john", "bill", "dave" ]</tt>.
|
8
|
-
class TextListField < ObjectField
|
9
|
-
def valueFromSQL(sqlString, lookupLink = true) #:nodoc:
|
10
|
-
if sqlString
|
11
|
-
sqlString.split ','
|
12
|
-
else
|
13
|
-
[]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def valueForSQL(objectValue) #:nodoc:
|
18
|
-
"'" + objectValue.join(',') + "'"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'lafcadio/objectField/DateTimeField'
|
2
|
-
|
3
|
-
module Lafcadio
|
4
|
-
class TimeStampField < DateTimeField #:nodoc:
|
5
|
-
def initialize(objectType, name = 'timeStamp', englishName = nil)
|
6
|
-
super( objectType, name, englishName )
|
7
|
-
@hideDisplay = true
|
8
|
-
@notNull = false
|
9
|
-
end
|
10
|
-
|
11
|
-
def dbWillAutomaticallyWrite
|
12
|
-
true
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'lafcadio/util/ContextualService'
|
2
|
-
|
3
|
-
module Lafcadio
|
4
|
-
class ObjectStore < ContextualService
|
5
|
-
class Cache #:nodoc:
|
6
|
-
def initialize( dbBridge )
|
7
|
-
@dbBridge = dbBridge
|
8
|
-
@objects = {}
|
9
|
-
@collections_by_query = {}
|
10
|
-
@commit_times = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
def hashByObjectType(objectType)
|
14
|
-
unless @objects[objectType]
|
15
|
-
@objects[objectType] = {}
|
16
|
-
end
|
17
|
-
@objects[objectType]
|
18
|
-
end
|
19
|
-
|
20
|
-
# Returns a cached domain object, or nil if none is found.
|
21
|
-
def get(objectType, pkId)
|
22
|
-
hashByObjectType(objectType)[pkId].clone
|
23
|
-
end
|
24
|
-
|
25
|
-
# Saves a domain object.
|
26
|
-
def save(dbObject)
|
27
|
-
hashByObjectType(dbObject.objectType)[dbObject.pkId] = dbObject
|
28
|
-
flush_collection_cache( dbObject.objectType )
|
29
|
-
end
|
30
|
-
|
31
|
-
def getByQuery( query )
|
32
|
-
unless @collections_by_query[query]
|
33
|
-
newObjects = @dbBridge.getCollectionByQuery(query)
|
34
|
-
newObjects.each { |dbObj| save dbObj }
|
35
|
-
@collections_by_query[query] = newObjects.collect { |dobj|
|
36
|
-
dobj.pkId
|
37
|
-
}
|
38
|
-
end
|
39
|
-
collection = []
|
40
|
-
@collections_by_query[query].each { |pkId|
|
41
|
-
dobj = get( query.objectType, pkId )
|
42
|
-
collection << dobj if dobj
|
43
|
-
}
|
44
|
-
collection
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns an array of all domain objects of a given type.
|
48
|
-
def getAll(objectType)
|
49
|
-
hashByObjectType(objectType).values.collect { |d_obj| d_obj.clone }
|
50
|
-
end
|
51
|
-
|
52
|
-
# Flushes a domain object.
|
53
|
-
def flush(dbObject)
|
54
|
-
hashByObjectType(dbObject.objectType).delete dbObject.pkId
|
55
|
-
flush_collection_cache( dbObject.objectType )
|
56
|
-
end
|
57
|
-
|
58
|
-
def flush_collection_cache( objectType )
|
59
|
-
@collections_by_query.keys.each { |query|
|
60
|
-
if query.objectType == objectType
|
61
|
-
@collections_by_query.delete( query )
|
62
|
-
end
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
def last_commit_time( domain_class, pkId )
|
67
|
-
by_domain_class = @commit_times[domain_class]
|
68
|
-
by_domain_class ? by_domain_class[pkId] : nil
|
69
|
-
end
|
70
|
-
|
71
|
-
def set_commit_time( d_obj )
|
72
|
-
by_domain_class = @commit_times[d_obj.objectType]
|
73
|
-
if by_domain_class.nil?
|
74
|
-
by_domain_class = {}
|
75
|
-
@commit_times[d_obj.objectType] = by_domain_class
|
76
|
-
end
|
77
|
-
by_domain_class[d_obj.pkId] = Time.now
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'lafcadio/objectStore/ObjectStore'
|
2
|
-
|
3
|
-
module Lafcadio
|
4
|
-
class Committer #:nodoc:
|
5
|
-
INSERT = 1
|
6
|
-
UPDATE = 2
|
7
|
-
DELETE = 3
|
8
|
-
|
9
|
-
attr_reader :commitType, :dbObject
|
10
|
-
|
11
|
-
def initialize(dbObject, dbBridge)
|
12
|
-
@dbObject = dbObject
|
13
|
-
@dbBridge = dbBridge
|
14
|
-
@objectStore = Context.instance.getObjectStore
|
15
|
-
@commitType = nil
|
16
|
-
end
|
17
|
-
|
18
|
-
def setCommitType
|
19
|
-
if @dbObject.delete
|
20
|
-
@commitType = DELETE
|
21
|
-
elsif @dbObject.pkId
|
22
|
-
@commitType = UPDATE
|
23
|
-
else
|
24
|
-
@commitType = INSERT
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def execute
|
29
|
-
setCommitType
|
30
|
-
@dbObject.lastCommit = getLastCommit
|
31
|
-
@dbObject.preCommitTrigger
|
32
|
-
if @dbObject.delete
|
33
|
-
dependentClasses = @dbObject.objectType.dependentClasses
|
34
|
-
dependentClasses.keys.each { |aClass|
|
35
|
-
field = dependentClasses[aClass]
|
36
|
-
collection = @objectStore.getFiltered( aClass.name, @dbObject,
|
37
|
-
field.name )
|
38
|
-
collection.each { |dependentObject|
|
39
|
-
if field.deleteCascade
|
40
|
-
dependentObject.delete = true
|
41
|
-
else
|
42
|
-
dependentObject.send( field.name + '=', nil )
|
43
|
-
end
|
44
|
-
@objectStore.commit(dependentObject)
|
45
|
-
}
|
46
|
-
}
|
47
|
-
end
|
48
|
-
@dbBridge.commit @dbObject
|
49
|
-
unless @dbObject.pkId
|
50
|
-
@dbObject.pkId = @dbBridge.lastPkIdInserted
|
51
|
-
end
|
52
|
-
@dbObject.postCommitTrigger
|
53
|
-
end
|
54
|
-
|
55
|
-
def getLastCommit
|
56
|
-
if @dbObject.delete
|
57
|
-
DomainObject::COMMIT_DELETE
|
58
|
-
elsif @dbObject.pkId
|
59
|
-
DomainObject::COMMIT_EDIT
|
60
|
-
else
|
61
|
-
DomainObject::COMMIT_ADD
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
require 'dbi'
|
4
|
-
require_gem 'log4r'
|
5
|
-
require 'lafcadio/util/LafcadioConfig'
|
6
|
-
|
7
|
-
module Lafcadio
|
8
|
-
class DbBridge #:nodoc:
|
9
|
-
@@dbh = nil
|
10
|
-
@@lastPkIdInserted = nil
|
11
|
-
@@dbName = nil
|
12
|
-
@@connectionClass = DBI
|
13
|
-
|
14
|
-
def DbBridge.setDbName(dbName)
|
15
|
-
@@dbName = dbName
|
16
|
-
end
|
17
|
-
|
18
|
-
def DbBridge._load(aString)
|
19
|
-
aString =~ /dbh:/
|
20
|
-
dbString = $'
|
21
|
-
begin
|
22
|
-
dbh = Marshal.load(dbString)
|
23
|
-
rescue TypeError
|
24
|
-
dbh = nil
|
25
|
-
end
|
26
|
-
new dbh
|
27
|
-
end
|
28
|
-
|
29
|
-
def DbBridge.flushConnection
|
30
|
-
@@dbh = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def DbBridge.setConnectionClass( aClass )
|
34
|
-
@@connectionClass = aClass
|
35
|
-
end
|
36
|
-
|
37
|
-
def DbBridge.disconnect
|
38
|
-
@@dbh.disconnect if @@dbh
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize(dbh = nil)
|
42
|
-
if dbh == nil
|
43
|
-
if @@dbh == nil
|
44
|
-
config = LafcadioConfig.new
|
45
|
-
dbName = @@dbName || config['dbname']
|
46
|
-
dbAndHost = nil
|
47
|
-
if dbName && config['dbhost']
|
48
|
-
dbAndHost = "dbi:Mysql:#{ dbName }:#{ config['dbhost'] }"
|
49
|
-
else
|
50
|
-
dbAndHost = "dbi:#{config['dbconn']}"
|
51
|
-
end
|
52
|
-
@@dbh = @@connectionClass.connect( dbAndHost, config['dbuser'],
|
53
|
-
config['dbpassword'] )
|
54
|
-
end
|
55
|
-
else
|
56
|
-
@@dbh = dbh
|
57
|
-
end
|
58
|
-
@dbh = @@dbh
|
59
|
-
ObjectSpace.define_finalizer( self, proc { |id| DbBridge.disconnect } )
|
60
|
-
end
|
61
|
-
|
62
|
-
def maybeLog(sql)
|
63
|
-
config = LafcadioConfig.new
|
64
|
-
if config['logSql'] == 'y'
|
65
|
-
sqllog = Log4r::Logger['sql'] || Log4r::Logger.new( 'sql' )
|
66
|
-
filename = File.join( config['logdir'], config['sqlLogFile'] || 'sql' )
|
67
|
-
outputter = Log4r::FileOutputter.new( 'outputter',
|
68
|
-
{ :filename => filename } )
|
69
|
-
sqllog.outputters = outputter
|
70
|
-
sqllog.info sql
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def commit(dbObject)
|
75
|
-
require 'lafcadio/objectStore/DomainObjectSqlMaker'
|
76
|
-
sqlMaker = DomainObjectSqlMaker.new(dbObject)
|
77
|
-
sqlMaker.sqlStatements.each { |sql, binds| executeCommit( sql, binds ) }
|
78
|
-
if sqlMaker.sqlStatements[0].first =~ /insert/
|
79
|
-
sql = 'select last_insert_id()'
|
80
|
-
result = executeSelect( sql )
|
81
|
-
@@lastPkIdInserted = result[0]['last_insert_id()'].to_i
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def executeCommit( sql, binds )
|
86
|
-
@dbh.do( sql, *binds )
|
87
|
-
end
|
88
|
-
|
89
|
-
def getCollectionByQuery(query)
|
90
|
-
require 'lafcadio/objectStore/SqlValueConverter'
|
91
|
-
objectType = query.objectType
|
92
|
-
coll = []
|
93
|
-
objects = []
|
94
|
-
result = executeSelect query.toSql
|
95
|
-
result.each { |row_hash|
|
96
|
-
converter = SqlValueConverter.new(objectType, row_hash)
|
97
|
-
obj = objectType.new converter
|
98
|
-
objects << obj
|
99
|
-
}
|
100
|
-
coll = coll.concat objects
|
101
|
-
coll
|
102
|
-
end
|
103
|
-
|
104
|
-
def executeSelect(sql)
|
105
|
-
maybeLog sql
|
106
|
-
begin
|
107
|
-
@dbh.select_all( sql )
|
108
|
-
rescue DBI::DatabaseError => e
|
109
|
-
raise $!.to_s + ": #{ e.errstr }"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def _dump(aDepth)
|
114
|
-
if @db.respond_to? '_dump'
|
115
|
-
dbDump = @db._dump
|
116
|
-
else
|
117
|
-
dbDump = @db.class.to_s
|
118
|
-
end
|
119
|
-
"dbh:#{dbDump}"
|
120
|
-
end
|
121
|
-
|
122
|
-
def lastPkIdInserted
|
123
|
-
@@lastPkIdInserted
|
124
|
-
end
|
125
|
-
|
126
|
-
def group_query( query )
|
127
|
-
row = executeSelect( query.toSql )[0]
|
128
|
-
result = []
|
129
|
-
row.each { |val|
|
130
|
-
if query.field_name != query.objectType.sqlPrimaryKeyName
|
131
|
-
a_field = query.objectType.getField( query.field_name )
|
132
|
-
result << a_field.valueFromSQL( val )
|
133
|
-
else
|
134
|
-
result << val.to_i
|
135
|
-
end
|
136
|
-
}
|
137
|
-
result
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
require 'dbi'
|
4
|
-
require_gem 'log4r'
|
5
|
-
require 'lafcadio/util/LafcadioConfig'
|
6
|
-
|
7
|
-
module Lafcadio
|
8
|
-
class DbBridge #:nodoc:
|
9
|
-
@@dbh = nil
|
10
|
-
@@lastPkIdInserted = nil
|
11
|
-
@@dbName = nil
|
12
|
-
@@connectionClass = DBI
|
13
|
-
|
14
|
-
def DbBridge.setDbName(dbName)
|
15
|
-
@@dbName = dbName
|
16
|
-
end
|
17
|
-
|
18
|
-
def DbBridge._load(aString)
|
19
|
-
aString =~ /dbh:/
|
20
|
-
dbString = $'
|
21
|
-
begin
|
22
|
-
dbh = Marshal.load(dbString)
|
23
|
-
rescue TypeError
|
24
|
-
dbh = nil
|
25
|
-
end
|
26
|
-
new dbh
|
27
|
-
end
|
28
|
-
|
29
|
-
def DbBridge.flushConnection
|
30
|
-
@@dbh = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def DbBridge.setConnectionClass( aClass )
|
34
|
-
@@connectionClass = aClass
|
35
|
-
end
|
36
|
-
|
37
|
-
def DbBridge.disconnect
|
38
|
-
@@dbh.disconnect if @@dbh
|
39
|
-
end
|
40
|
-
|
41
|
-
def initialize(dbh = nil)
|
42
|
-
if dbh == nil
|
43
|
-
if @@dbh == nil
|
44
|
-
config = LafcadioConfig.new
|
45
|
-
dbName = @@dbName || config['dbname']
|
46
|
-
dbAndHost = nil
|
47
|
-
if dbName && config['dbhost']
|
48
|
-
dbAndHost = "dbi:Mysql:#{ dbName }:#{ config['dbhost'] }"
|
49
|
-
else
|
50
|
-
dbAndHost = "dbi:#{config['dbconn']}"
|
51
|
-
end
|
52
|
-
@@dbh = @@connectionClass.connect( dbAndHost, config['dbuser'],
|
53
|
-
config['dbpassword'] )
|
54
|
-
end
|
55
|
-
else
|
56
|
-
@@dbh = dbh
|
57
|
-
end
|
58
|
-
@dbh = @@dbh
|
59
|
-
ObjectSpace.define_finalizer( self, proc { |id| DbBridge.disconnect } )
|
60
|
-
end
|
61
|
-
|
62
|
-
def maybeLog(sql)
|
63
|
-
config = LafcadioConfig.new
|
64
|
-
if config['logSql'] == 'y'
|
65
|
-
sqllog = Log4r::Logger['sql'] || Log4r::Logger.new( 'sql' )
|
66
|
-
filename = File.join( config['logdir'], config['sqlLogFile'] || 'sql' )
|
67
|
-
outputter = Log4r::FileOutputter.new( 'outputter',
|
68
|
-
{ :filename => filename } )
|
69
|
-
sqllog.outputters = outputter
|
70
|
-
sqllog.info sql
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def commit(dbObject)
|
75
|
-
require 'lafcadio/objectStore/DomainObjectSqlMaker'
|
76
|
-
sqlMaker = DomainObjectSqlMaker.new(dbObject)
|
77
|
-
sqlMaker.sqlStatements.each { |sql, binds| executeCommit( sql, binds ) }
|
78
|
-
if sqlMaker.sqlStatements[0].first =~ /insert/
|
79
|
-
sql = 'select last_insert_id()'
|
80
|
-
result = executeSelect( sql )
|
81
|
-
@@lastPkIdInserted = result[0]['last_insert_id()'].to_i
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def executeCommit( sql, binds )
|
86
|
-
@dbh.do( sql, *binds )
|
87
|
-
end
|
88
|
-
|
89
|
-
def getCollectionByQuery(query)
|
90
|
-
require 'lafcadio/objectStore/SqlValueConverter'
|
91
|
-
objectType = query.objectType
|
92
|
-
coll = []
|
93
|
-
objects = []
|
94
|
-
result = executeSelect query.toSql
|
95
|
-
result.each { |row_hash|
|
96
|
-
converter = SqlValueConverter.new(objectType, row_hash)
|
97
|
-
obj = objectType.new converter
|
98
|
-
objects << obj
|
99
|
-
}
|
100
|
-
coll = coll.concat objects
|
101
|
-
coll
|
102
|
-
end
|
103
|
-
|
104
|
-
def executeSelect(sql)
|
105
|
-
maybeLog sql
|
106
|
-
begin
|
107
|
-
@dbh.select_all( sql )
|
108
|
-
rescue DBI::DatabaseError => e
|
109
|
-
raise $!.to_s + ": #{ e.errstr }"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def _dump(aDepth)
|
114
|
-
if @db.respond_to? '_dump'
|
115
|
-
dbDump = @db._dump
|
116
|
-
else
|
117
|
-
dbDump = @db.class.to_s
|
118
|
-
end
|
119
|
-
"dbh:#{dbDump}"
|
120
|
-
end
|
121
|
-
|
122
|
-
def lastPkIdInserted
|
123
|
-
@@lastPkIdInserted
|
124
|
-
end
|
125
|
-
|
126
|
-
def group_query( query )
|
127
|
-
row = executeSelect( query.toSql )[0]
|
128
|
-
result = []
|
129
|
-
row.each { |val|
|
130
|
-
if query.field_name != 'pkId'
|
131
|
-
a_field = query.objectType.getField( query.field_name )
|
132
|
-
result << a_field.valueFromSQL( val )
|
133
|
-
else
|
134
|
-
result << val.to_i
|
135
|
-
end
|
136
|
-
}
|
137
|
-
result
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|