summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-07-08 10:00:08 -0500
committerOmar Roth <omarroth@protonmail.com>2019-07-08 10:00:08 -0500
commit5fd3ed782f5577b685e7de79a8bdf551dc64e13b (patch)
treefa5ca97c4182924bb0355bcc4af26a7c519143cd
parentc34a24b633417084ec0f3ebfc564a55f5dfb960f (diff)
downloadinvidious-5fd3ed782f5577b685e7de79a8bdf551dc64e13b.tar.gz
invidious-5fd3ed782f5577b685e7de79a8bdf551dc64e13b.tar.bz2
invidious-5fd3ed782f5577b685e7de79a8bdf551dc64e13b.zip
Add fix for #600
-rw-r--r--src/invidious/helpers/handlers.cr38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr
index 216f9b5d..7fbfb643 100644
--- a/src/invidious/helpers/handlers.cr
+++ b/src/invidious/helpers/handlers.cr
@@ -225,3 +225,41 @@ class HTTP::Client
response
end
end
+
+# https://github.com/will/crystal-pg/pull/171
+class PG::Statement < ::DB::Statement
+ protected def perform_query(args : Enumerable) : ResultSet
+ params = args.map { |arg| PQ::Param.encode(arg) }
+ conn = self.conn
+ conn.send_parse_message(@sql)
+ conn.send_bind_message params
+ conn.send_describe_portal_message
+ conn.send_execute_message
+ conn.send_sync_message
+ conn.expect_frame PQ::Frame::ParseComplete
+ conn.expect_frame PQ::Frame::BindComplete
+ frame = conn.read
+ case frame
+ when PQ::Frame::RowDescription
+ fields = frame.fields
+ when PQ::Frame::NoData
+ fields = nil
+ else
+ raise "expected RowDescription or NoData, got #{frame}"
+ end
+ ResultSet.new(self, fields)
+ rescue IO::Error
+ raise DB::ConnectionLost.new(connection)
+ end
+
+ protected def perform_exec(args : Enumerable) : ::DB::ExecResult
+ result = perform_query(args)
+ result.each { }
+ ::DB::ExecResult.new(
+ rows_affected: result.rows_affected,
+ last_insert_id: 0_i64 # postgres doesn't support this
+ )
+ rescue IO::Error
+ raise DB::ConnectionLost.new(connection)
+ end
+end