Rails 3.1 broke sorting for MySql::Time - mysql

I just upgrading from Rails 3 to 3.1, and am getting this error:
NoMethodError (undefined method `<=>' for #<Mysql::Time:2011-01-12 00:00:00>):
on this line:
payments = Payment.all( :select => 'date(created_at) as day, amount', :order => 'created_at',
:conditions => ["status = ?"], 1)
payments.group_by(&:day).sort
Any ideas how to fix?

You could try to explicitly cast the rows to ruby Time objects:
payments.group_by(&:day).sort{ |x,y| Time.parse(x) <=> Time.parse(y) }

Fixed it. I switched to the mysql2 gem (https://github.com/brianmario/mysql2), and that resolved the issue while keeping performance.

Related

Use of undefined constant SIGKILL - assumed 'SIGKILL' in Laravel 5.7 queue

I'm getting this error "Use of undefined constant SIGKILL - assumed 'SIGKILL'" from my AJAX request, that starts this artisan command ->
Artisan::call('queue:work', [
'connection' => 'database',
'--memory' => '700',
'--tries' => '1',
'--timeout' => '35000',
'--queue' => 'updates'
]);
I'm using Laravel 5.7 as framework for application.
Jobs are managed from database, configuration ->
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 18000,
],
Problem appeared recently.. That is weird, because troubles wasn't here before and all this "system" worked just fine. Now worker get some jobs done just fine, but then it drops to error, and writes to table "failed_jobs" in DB this ->
ErrorException: PDOStatement::execute(): MySQL server has gone away in /srv/migration-xxxxxx-xxxx-xxxxxx/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
As DB I'm using Microsoft Azure MySQL DB. Microsoft specialist after consultation find nothing .. server is working correctly. Queries are just fine, not that big to fail.
Please help, don't know what to do, or what is wrong...

Ruby Active Record Mysql Error

It seems like there are alot of tutorials online for using ruby to interact with mysql. But none of them work for me. Do I not have something installed correctly? Could someone tell me what I am doing wrong? I will try to put down as much relevant information as I can. I am relatively new to ruby (6 months).
This is my Error:
dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
Referenced from: /Library/Ruby/Gems/2.0.0/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_get_client_info
Referenced from: /Library/Ruby/Gems/2.0.0/gems/mysql-2.9.1/lib/mysql/mysql_api.bundle
Expected in: flat namespace
Trace/BPT trap: 5
This is my sample script:
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter=> "mysql",
:host => "localhost",
:database=> "#####",
:username => "#####",
:password => "#####"
)
class Rubyist < ActiveRecord::Base
end
Rubyist.create(:name => 'Luc Juggery', :city => "Nashville, Tenessee")
Rubyist.create(:name => 'Sunil Kelkar', :city => "Pune, India")
Rubyist.create(:name => 'Adam Smith', :city => "San Fransisco, USA")
I have the tables created in mysql. I am using the correct username, host, password, and database name. I have a table names Rubyist that has city and name columns.
gem list shows I have activerecord 4.1.1, mysql 2.9.1, mysql2 0.3.16
I have ruby installed ruby -v shows: ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
I am using a Mac

An issue when unixodbc dynamically linked with ltdl library?

all:
I am testing unixODBC in Solaris 10 environments, and find if libodbc and MyODBC driver are dynamically linked with libltdl.so:
ldd /usr/lib/libodbc.so.2
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
ldd /data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
sometimes it will connect MySQL server failed when starting up application. The log likes this:
[ODBC][6738][1361325895.588941][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
[ODBC][6738][1361325895.588979][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
After a while, the application runs OK.
But if libodbc and MyODBC driver aren't dynamically linked with libltdl.so:
ldd /usr/local/lib/libodbc.so.2
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
ldd /data1/susie/mysql/tools/test_static_modify/mysql-connector-odbc-5.2.3-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/local/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/local/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
The application runs always OK..
So I think it may be a potential issue in unixODBC. Could anyone help to check it? Thanks very much in advance!
Best Regards
Nan Xiao
All unixODBC does is call dlopen and dlsym from libltdl, I wonder if there is some statics in the lib that is causing the problem. If you don't build unixODBC to use a exernal libltdl it uses its own version (from libtool), so again, it may be a conflict with them both hitting the same lib. You say you are using Solaris. Is the libltdl you are linking with from Sun?
What might be interesting is if you can get it to fail under truss so we could see just what the "file not found" is caused by.
I also wonder just what the MySQL driver uses libltdl for?

exception_notification: smtp not working

I am using Rails 3.2.5 and exception_notification gem. In production mode, I am generally sending emails using PostMarkApp's postmark-rails gem.
Initially, I got a View error from exception_notification gem stating
ActionView::Template::Error (code converter not found (UTF-8 to UTF-16))
so based on exception_notification gem raises ActionView::Template::Error (code converter not found (UTF-8 to UTF-16)) only on Heroku production mode, I moved to
gem 'exception_notification', git: 'git://github.com/alanjds/exception_notification.git'
This solved that bug. Now, I want the gem to send emails from my gmail account instead of using PostMarkApp credits, so I added the following to my production.rb, yet Exception Notification attempts to send email only from Post Mark App. Why is this setting not working?
config.middleware.use ExceptionNotifier,
sender_address: 'noreply#mydomain.com',
exception_recipients: 'myemail#mydomain.com',
sections: %w{current_user} + ExceptionNotifier::Notifier.default_sections,
ignore_crawlers: %w{Googlebot bingbot},
email_format: true,
normalize_subject: true,
smtp_settings: {
:address => "smtp.gmail.com",
:port => "587",
:domain => "www.gmail.com",
:user_name => "myemail#gmail.com",
:password => "mypassword",
:authentication => "plain",
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_key => "_____" }
For some reason it appears that SMTP delivery does NOT work in the development environment. I tried a number of different settings and was never able to get this to work. It DOES however work in my other environments. Older posts seem to indicate this as well:
http://www.ruby-forum.com/topic/64776
http://www.devchix.com/2008/12/09/how-to-see-exception_notification-plugin-work-in-development-mode/
In development, I am using the following in my development.rb:
config.action_mailer.delivery_method = :letter_opener
config.middleware.use ExceptionNotifier,
:sender_address => 'test#test.com',
:exception_recipients => 'recipient#test.com'
In my "staging" environment, I am using the following in my staging.rb:
config.action_mailer.delivery_method = :smtp
config.middleware.use ExceptionNotifier,
:sender_address => 'test#test.com',
:exception_recipients => 'recipient#test.com'
The staging.rb acquires it's SMTP settings from an initializer I have the uses SendGrid for SMTP:
ActionMailer::Base.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 25,
:domain => "test.com",
:user_name => "user_name",
:password => "password",
:authentication => "plain"
}
Try the suggestion at http://www.scottw.com/multiple-smtp-servers-with-action-mailer
or at Rails ActionMailer with multiple SMTP servers

rails select only 2 columns error

script/console output:
>> User.find(:first, :select => '`email`, `pass`, `login`, `id`')
=> #<User pass: "e10adc3949ba59abbe56e057f20f883e", email: "fakemail#bla-bla-bla.com">
>> User.find(:first, :select => '`pass`, `login`, `id`')
=> #<User login: "ostap", pass: "e10adc3949ba59abbe56e057f20f883e">
how i can fix it?
Unix hosting, Ruby 1.8.7, Rails 2.3.5, MySQL 5.1.46
in mysql console all fine...
Try changing ":select => 'pass, login, id'" to :select => 'email, pass, login, id'; i.e. remove the backticks around the fields. I think the backticks in your argument are throwing off the select. Here is the API dock for the find command that lead me to that conclusion.