Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-21 02:45
connect.............ok
Francis,

I think you are right. Didn't bother to run the test script earlier - result below.

create_db...........ok
create_table........ok
insert..............ok
select.............../t/40select.rb:4:in `fetch_hash': NULL pointer given (ArgumentError)
from ./t/40select.rb:4
from test.rb:23:in `load'
from test.rb:23
from test.rb:19:in `each'
from test.rb:19

Many thanks,
Keith

By: Francis Hwang
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-21 02:11
Wow, that's wierd. For some reason there's both a Ruby-MySQL and a MySQL-Ruby. And they're coded by the same guy. I just emailed him asking for clarification on the two separate projects, but in the meantime I'd recommend you do this:

1. Uninstall MySQL-Ruby.

2. Download and install Ruby-MySQL (http://www.tmtm.org/ja/ruby/mysql/README_en.html).


By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-21 01:48
Francis,

I downloaded the lastest tar file - mysql-ruby-2.4.5.tar.gz and compiled it as per normal.

Which version are you using now?

Cheers,
Keith

By: Francis Hwang
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-20 17:37
Keith:

So it looks like the result set responds to .each but not .each_hash ... What version of Ruby-MySQL are you using?

Francis

By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-19 04:54
Hi Francis,

The problem seems to be in the code below my additions:

# When passed a query, executes that query and returns a Collection.
def getCollectionByQuery(query)
require 'lafcadio/objectStore/Collection'
require 'lafcadio/objectStore/SqlValueConverter'
objectType = query.objectType
coll = Collection.new objectType
objects = []
result = executeQuery query.toSql
------------------------------------------------
#result.each do |row|
# puts row[3]
#end
#----> result object working

------------------------------------------------
result.each_hash { |row_hash|
converter = sqlValueConverter.new(objectType, row_hash)
obj = objectType.new converter.execute
objects << obj
}
coll = coll.concat objects
coll
end


Could you explain the code below my additions.
Many thanks.

Cheers,
Keith



By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-19 04:46
Francis,

I found the object and method and added some code.

def executeQuery(sql)
maybeLog sql
begin
result = @db.query sql
rescue MysqlError
raise $!.to_s + ": #{sql}"
end
------------------------------------------
result.each do |row|
puts row[3]
end
------------------------------------------
result
end

It seems to work at this point in your object - I get all the columns perfectly. I will try to locate where result end up in.

Cheers,
Keith

By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-19 04:23
Francis,

1. I got "select * from patient" (without the ";" added). Does that cause a problem?

2. Which object & method receive the sql and how do i see the resultset or output returned from mysql.

Thanks.
Keith

By: Francis Hwang
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-19 03:57
Keith,

If you want to turn on SQL logging, right now you have to do this:

1. Find the file lafcadio/objectStore/DBBridge.rb, and uncomment the Logger line in maybeLog so it looks like this:

def maybeLog(sql)
require 'lafcadio/util/Logger'
Logger.log sql, 'sql'
end

2. Create a directory for your logs, and make it world-writeable:

mkdir ~/test/logdir
chmod 0666 ~/test/logdir

3. Add a reference to this in your config.dat file:

logdir:~/test/logdir/

So if you want to see the SQL that's generated you can read it in that directory.

I think it's still worth looking at that table's create statement. Also, what version of Ruby-MySQL are you using? I don't mind helping you with this problem -- if this means I have to fix something I want to know about it as soon as possible.

Francis

By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-19 03:39
Hi Francis,

Many thanks for your help. Rather than impose further on you, I would be very grateful if you could show me how to debug to get the sql generated and resultset from using your domain object. I have no problem connecting to mysql using the ruby wrapped c driver. However I really would like your domain object to work for me.

Cheers,
Keith

By: Francis Hwang
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-18 23:29
Yeah, that all looks okay. Maybe there's something strange with the MySQL table? Can you supply the create statement you used, or get one with mysqldump?

By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-18 02:31
Hi Francis,

Many thanks for the help. As requested:

-------------------------------------------------
config.rb
-------------------------------------------------
require 'lafcadio/util/LafcadioConfig'

# Tell the LafcadioConfig class where to find its data file
LafcadioConfig.setFilename "/home/keith/ruby/examples/config.dat"

----------------------------------------
config.dat
----------------------------------------
dbuser: xxxxx
dbpassword: xxxxx
dbname: xxxxx
dbhost:localhost
domainDirs:/home/keith/ruby/examples/domain/

ruby version 1.8, Redhat 9.0, Ximian Desktop 2

Cheers,
Keith

By: Francis Hwang
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-18 01:03
Hi Keith:

I tried duplicating the problem at home but it seems to work fine for me. Two things:

1. What version of ruby are you using? (Type "ruby -v" to find out.)

2. What's in the files config.rb and config.dat? (Remember to X out the password in config.dat before posting it ...)

Francis

By: Keith Kee
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-17 08:03
Hi Francis,

Many thanks for the quick reply. I post the output and the two files for your perusal.

output
-------------------------------------------------
ruby test2.rb
start
/usr/local/lib/ruby/site_ruby/1.8/lafcadio/objectStore/DbBridge.rb:73:in `each_hash': NULL pointer given (ArgumentError)
from /usr/local/lib/ruby/site_ruby/1.8/lafcadio/objectStore/DbBridge.rb:73:in `getCollectionByQuery'
from /usr/local/lib/ruby/site_ruby/1.8/lafcadio/objectStore/Retriever.rb:38:in `getAll'
from /usr/local/lib/ruby/site_ruby/1.8/lafcadio/objectStore/ObjectStore.rb:64:in `getAll'
from test2.rb:9
---------------------------------------------
test2.rb
---------------------------------------------
#!/usr/bin/ruby

require 'config'
require 'lafcadio/objectStore/ObjectStore'
require 'domain/Patient'

puts 'start'
objectStore = ObjectStore.getObjectStore
p = objectStore.getAll Patient

-------------------------------------------
Patient.rb
-------------------------------------------
require 'lafcadio/domain/DomainObject'
require 'lafcadio/objectField/TextField'
require 'lafcadio/objectField/DateField'

class Patient < DomainObject
def Patient.classFields
fields = []
fields << TextField.new(self, 'name')
fields << TextField.new(self, 'nric')
end
def Patient.sqlPrimaryKeyName()
return 'id'
end
def Patient.tableName()
return 'patient'
end
end

BTW, the table name is patient (no CAPITAL P).
I tried "p = objectstore.getpatient 1" with the same error.

Best,
Keith


By: Francis Hwang
RE: Domain Object - sequence and completeness [ reply ]  
2003-09-17 04:31
Hi Keith,

1. Order isn't important. The objId field doesn't have to be included. However, if you're using a different primary key you need to override the class's sqlPrimaryKeyName method. For example:

class Account < DomainObject
def Account.sqlPrimaryKeyName
"id"
end
end

But note that although it's called "id" in your database, it's still called "objId" in your Ruby code. So:

objId = myAccount.objId

I actually wanted to use "id" when first designing this, but it turns out that the method "id" is already defined for every object in Ruby. Override that behavior and you get lots of trouble.

I'm not sure why you'd get a null pointer error ... can you post the code you tried?

2. At this time, there is unfortunately no automatic domain object definition. It's in the works, but I can't say when it'll happen.

Francis

By: Keith Kee
Domain Object - sequence and completeness? [ reply ]  
2003-09-17 02:05
Hi,

I am a newbie with ruby, mysql and your lafcadio - looks very promising to me :)

1. When declaring the domain object - must it follow the db field sequence and must it include all the fields including the primary key (objid) or id in my case?

I keep getting a null pointer error when accessing the domain object field - i only declared one field for testing purposes.

2. Is there a function to automate the creation of domain objects? How do I verify that it was created properly?

Cheers,
Keith