Skip to content

Instantly share code, notes, and snippets.

@richardsondx
Created August 7, 2012 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardsondx/3282515 to your computer and use it in GitHub Desktop.
Save richardsondx/3282515 to your computer and use it in GitHub Desktop.
Sequel::DatabaseError - PG::Error: ERROR: invalid input syntax for integer: ""
require 'sequel'
require 'sequel/extensions/pagination'
# ...
DB = Sequel.connect(ENV['DATABASE_URL'] || 'postgres://localhost/wind.db')
# ...
2012-08-07T06:46:04+00:00 app[web.1]: Sequel::DatabaseError - PG::Error: ERROR: invalid input syntax for integer: ""
2012-08-07T06:46:04+00:00 app[web.1]: :
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:145:in `block in execute_query'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/database/logging.rb:33:in `log_yield'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:145:in `async_exec'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:145:in `execute_query'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:132:in `block in execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:111:in `check_disconnect_errors'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:132:in `execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:234:in `block (2 levels) in execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:372:in `_execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:234:in `block in execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:379:in `check_database_errors'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/database/connecting.rb:229:in `block in synchronize'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/connection_pool/threaded.rb:105:in `hold'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/database/connecting.rb:229:in `synchronize'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:234:in `execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:483:in `fetch_rows'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/dataset/actions.rb:744:in `execute'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/model/base.rb:785:in `primary_key_lookup'
2012-08-07T06:46:04+00:00 app[web.1]: /app/routes.rb:59:in `block (2 levels) in <top (required)>'
2012-08-07T06:46:04+00:00 app[web.1]: /app/helpers.rb:29:in `if_logged'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/model/base.rb:124:in `[]'
2012-08-07T06:46:04+00:00 app[web.1]: /app/routes.rb:58:in `block in <top (required)>'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `[]'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1212:in `block in compile!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (3 levels) in route!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:801:in `route_eval'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:785:in `block (2 levels) in route!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:822:in `block in process_route'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:784:in `block in route!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `catch'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:820:in `process_route'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `each'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:783:in `route!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:886:in `dispatch!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `block in invoke'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `block in call!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `invoke'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:871:in `catch'
2012-08-07T06:46:04+00:00 heroku[router]: POST morning-peak-7383.herokuapp.com/post dyno=web.1 queue=0 wait=0ms service=50ms status=500 bytes=30
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:719:in `call!'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:705:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
2012-08-07T06:46:04+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in `service'
2012-08-07T06:46:04+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2012-08-07T06:46:04+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2012-08-07T06:46:04+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2012-08-07T06:46:04+00:00 app[web.1]: 70.29.80.117 - - [07/Aug/2012 06:46:04] "POST /post HTTP/1.1" 500 30 0.0457
require 'RedCloth'
def partial(view)
erb :"_#{view}", :layout => false
end
def go_home
redirect '/'
end
def message(text)
@message = text
end
def auth?(code)
code == $settings.code
end
def login(log = true)
session[:logged] = log
end
def logged?
session[:logged]
end
def if_logged
if logged?
yield if block_given?
else
go_home
end
end
def env
request['ENV']
end
def host
"http://#{env['HTTP_HOST']}"
end
def path
"#{host}#{env['REQUEST_PATH']}"
end
def to_link(title)
title.gsub(' ', '-').urlize
end
def textile(text)
RedCloth.new(text).to_html
end
def today
Date.today
end
def date(the_date)
the_date.strftime '%Y-%m-%d'
end
def edit_link(path, id)
" <a class='edit' href='/#{path}/#{id}'>[Edit]</a>" if logged?
end
def next_page
count = Post.count
if params[:page]
page = params[:page].to_i
if count > page * PAGE_SIZE
page + 1
end
elsif count > PAGE_SIZE
2
end
end
def feed_url
feed = $settings.feed
if feed.nil? or feed.empty?
'/feed'
else
feed
end
end
def wind_link
'http://github.com/wagnerandrade/wind'
end
def style
if File.exist? 'public/custom/style.css'
'/custom/style.css'
else
'/style.css'
end
end
def feed(posts)
builder do |xml|
xml.instruct! :xml, :version => '1.0'
xml.rss :version => "2.0" do
xml.channel do
xml.title $settings.name
xml.description $settings.title
xml.link host
posts.each do |post|
xml.item do
xml.title post.title
xml.link "#{host}/#{post.link}"
xml.description textile(post.text)
xml.pubDate post.date.rfc822()
xml.guid "#{host}/#{post.link}"
end
end
end
end
end
end
class Sequel::Model
def self.sync
schema.columns.each do |column|
begin
DB.alter_table table_name do
add_column column[:name], column[:type]
end
puts "Sync column #{column[:name]}."
rescue
end
end
end
end
class Post < Sequel::Model
set_schema do
primary_key :id
String :title
String :text
datetime :date
String :link
end
unless table_exists?
create_table
create(
:title => 'Welcome!',
:text => File.open('README.textile', 'r') { |file| file.read },
:date => Time.now,
:link => 'welcome'
)
end
sync
def self.ordered(page = 1)
filter.order(:date.desc).paginate(page.to_i, PAGE_SIZE)
end
def self.search(q)
value = "%#{q}%"
filter(:title.like(value) | :text.like(value)).order(:date.desc)
end
def self.with_link(value)
filter(:link => value).order(:date.desc)
end
end
get '/post/new' do
if_logged do
@post = Post.new
erb :post
end
end
post '/post' do
if_logged do
post = Post[params[:id]] || Post.new
post.title = params[:title]
post.text = params[:text]
unless post.id
post.date = Time.now
post.link = to_link params[:title]
end
if params[:action] == 'save'
post.save
go_home
elsif params[:action] == 'preview'
@posts = [] << post
erb :index
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment