Database error

Hi i am new to ruby on rails. I am using RMail which is ruby mail to
read the email that i fetch from. When the rmail read the email it will
insert the data inside the email to the database which i have created in
the first place. However i don't wish to have duplicate data inside the
database and i found out that every email have it own unique message-id.
But i does not know how to validate the new email's message-id with the
one in the database whether there is the same data inside the database.

For example,

My new email the message-id is jKqhYh15424 but there is the same
message-id inside the database and which i don't wish to insert the new
data into the database..

Help. Thanks.

Wawa

HI,

Hi i am new to ruby on rails. I am using RMail which is ruby mail to
read the email that i fetch from. When the rmail read the email it will
insert the data inside the email to the database which i have created in
the first place. However i don't wish to have duplicate data inside the
database and i found out that every email have it own unique message-id.
But i does not know how to validate the new email's message-id with the
one in the database whether there is the same data inside the database.

For example,

My new email the message-id is jKqhYh15424 but there is the same
message-id inside the database and which i don't wish to insert the new
data into the database..

Well, if you store emails for example in "Email" model ("emails"
collumn in
database), then you can easily find out if such email exists in your
database
by using ActiveRecord::count method. For example if message-id is
stored in
"message_id" collumn:

if Email.count(:conditions => ["message_id = ?", 1234]) > 0
  # we have email in database! do nothing!
else
  # insert email in database
end

Thi should do the trick.

if Email.count(:conditions => ["message_id = ?", 1234]) > 0
  # we have email in database! do nothing!
else
  # insert email in database
end

Is the if ["message_id = ?", 1234]) > 0 hard-coded. As i will have
different kind of emails been send everyday. So there will be quite a
lot of different message_id i got to validate with. Help. Thanks.

Wawa

HI,

Well, if you store emails for example in "Email" model ("emails"
collumn in
database), then you can easily find out if such email exists in your
database
by using ActiveRecord::count method. For example if message-id is
stored in
"message_id" collumn:

Or slightly more concisely ( and faster in cases where there could be
more than one matching row)

Email.exists? :conditions =>...

Fred

HI,

Or slightly more concisely ( and faster in cases where there could be
more than one matching row)

Email.exists? :conditions =>...

True, true!

> if Email.count(:conditions => ["message_id = ?", 1234]) > 0
> # we have email in database! do nothing!
> else
> # insert email in database
> end

You don't have to hardcoder 1234, just use variable there or
params[:message_id] or whatever you like instead of 1234.

Hi newbie is here. Ok thanks anyway. I got another error.

I got this sql query.

mysql = my.query("select messageID from maps where
DateTime=\'#{messageId}'")

the messageID is the database columns name while the messageId is i read
from the messageId = message.header['Message-id']. whish is a RMail
method of reading the email header.

When i do print mysql, it print out #<Mysql::Result:0xb7f49310>. Is this
a binary data. So how to i convert into a string. Help. Thanks.

Wawa