Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

$links_db->type->{"Add_Date"} reports field type incorrectly

(Page 1 of 2)
> >
Quote Reply
$links_db->type->{"Add_Date"} reports field type incorrectly
The $links_db->type->{"Add_Date"} (basically the type() method) reports field type incorrectly right from the def file, and not from the SQL table itself.
DATETIME type does not exists in LSQL so, I had to change the field type of Add_Date manually in database from DATE to DATETIME.

The only solution would be to use the DBI object, what GT::SQL uses internally, but it can not accessed outside from GT::SQL. Frown
I do not want to open a new db connection just to query a field type.

Anybody knows about an internal solution using GT::SQL?
Any ideas?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
>>
what GT::SQL uses internally, but it can not accessed outside from GT::SQL.
<<

It can be accessed anywhere by using:

use Links qw/$DB/;
Quote Reply
Re: [Paul] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Paul, I'm afraid it is not true. It is only the database handler of GT::SQL only.
If I could access the $dbh object of DBI, then I should able to call table_info method, then print it:
my $sth = $DB->table_info;
print "<br>\n sth: " . Dumper(\$sth) . "\n";


However I get the error:
GT::SQL (2712): Unknown method 'table_info' called at ...

Well, I'm still learning the DBI and the object oriented programming, but I think I'm right this time.
Let me know if I'm wrong. At least I learn something new.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
The DATETIME type exists in LSQL, it's only not there in the admin area.

In a plugin, you can just do something like:
Code:
$DB->editor('Links')->alter_col( Add_Date => { type => 'DATETIME' })

I hope this helps.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Dump the $DB object if you are unsure of what it contains.
Quote Reply
Re: [Paul] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Oh, you deleted your previous post.

Anyway the method table_info() does not exists.

If the $DB object would be a DBI object, then it should have a table_info() method.

If you are sure, you are right, then please advice me a solution how to get the correct type of a table field?
I need just a solution.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
I don't see what the problem is.

The field type is stored correctly in the def file, so you can just read it off from there. Of course if you update it manually outside of Links SQL, then you will first have to resync the database.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Ok. I was not exact. The DATETIME is missing from the Admin interface.

But the type method is getting the type info based on the def files, not from the database table itself.
Therefore if a def file has DATE for a field, but the truth is, that the field is DATETIME, then I will get the result DATE, and not DATETIME Frown.

That's my big problem.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
The truth also is that if you change the field definition outside of Links SQL then you should resync the database. After you do that, the def file will have "DATETIME" in it.

I really don't see your big problem here.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
>>
Anyway the method table_info() does not exists.

If the $DB object would be a DBI object, then it should have a table_info() method.
<<

Yeah but it isn't a dbi object its a GT::SQL object so you have to create a work around :)

So why not use the "schema" hashref or do as Yogi suggested :)

Last edited by:

Paul: Aug 30, 2002, 4:14 AM
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Here's some code for your future reference:

Code:
print Dumper($DB->table('Links'));
Quote Reply
Re: [Paul] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
I do actively use Dumper. But thanks.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
I wasn't referring to using Dumper() I was referring to what I was dumping Wink ...try it out and see what it produces.

Last edited by:

Paul: Aug 30, 2002, 4:26 AM
Quote Reply
Re: [Paul] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Quote:
The truth also is that if you change the field definition outside of Links SQL then you should resync the database. After you do that, the def file will have "DATETIME" in it.
Yogi,
Yes, this should work. This is a good workaround for the problem. Cool
It is possible that I will use this, if there will be no other solution.
However I would like to avoid to touch the def files, if not needed.



Paul,
Thanks for the info Wink
Well, the unfortunately the "schema" hashref always contains the info from def files...
See that hash part from {schema}->{cols}->{Add_Date}:
...
'Add_Date' => {
'not_null' => '1',
'form_type' => 'HIDDEN',
'form_size' => '20',
'weight' => '',
'regex' => '',
'form_display' => 'Date field',
'file_save_in' => '',
'file_save_scheme' => 'HASHED',
'file_max_size' => '',
'pos' => '5',
'type' => 'DATE'
},
...

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
>>
Well, the unfortunately the "schema" hashref always contains the info from def files...
<<

Yes I know. But if you keep your database re-sync'd properly as yogi suggested it will be accurate.
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
This is not a workaround, but the solution.Wink

The def files are vital for the functioning of Links SQL, they should always be up to date. You don't have to touch the def files, you only have to do resync after changing anything outside of Links SQL.

And as I explained above, from within a plugin, you can do everything you want.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
As Microsoft says, it is not bug, it is a feature Wink Wink Wink Laugh Laugh Cool

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [yogi] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Do you know, how the resync can be done?

I found a few functions for this:
GT::SQL::Creator::load_table, GT::SQL::Table::reload
GT::SQL::Admin::editor_update_def

editor_update_def should be the solution, but it seems it can not called independently, just from the admin interface.
So IMHO, I should create my own function with content of editor_update_def.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...

Last edited by:

webmaster33: Aug 30, 2002, 5:16 AM
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
When I say resync database, I mean clicking on the "Resync Database" link that is on the bottom of the page in "Database -> Links -> Properties". You have to do it manually.

If you alter columns, or add new columns from within a plugin, then you don't need to resync, because GT::SQL takes care of this automatically.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Oh, really?
If I do changes in a table from a plugin, it GT::SQL will handle the def resync automatically? Shocked Cool

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Of course.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Great! Thanks!

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
BTW, if you are going to store times, you might want to store the seconds as integers (INT). Have a look at this thread:
http://gossamer-threads.com/...rum.cgi?post=204269;

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Thanks, but no. I do not want to store times in seconds.
Until I do the the expiration based on days, I will not need to store dates in seconds.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] $links_db->type->{"Add_Date"} reports field type incorrectly In reply to
Hi,

Quote:
The $links_db->type->{"Add_Date"} (basically the type() method) reports field type incorrectly right from the def file, and not from the SQL table itself.


This is the proper behavior, as otherwise you run into problems because Oracle calls an INT a NUMBER, and it calls a TEXT field a CLOB. The point of the def file is to provide a common interface so you can work on a TEXT field and not worry about the differences between Oracle or MS SQL. Look at GT/SQL/Type.pm to see a list of types GT::SQL supports.

I'll look at updating the admin area so it has DATETIME in the editor.

Cheers,

Alex
--
Gossamer Threads Inc.
> >