Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some warnings #44

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ provides(Yum, "libpq5", libpq)
provides(Yum, "postgresql-libs", libpq)
provides(Pacman, "postgresql-libs", libpq)

@osx_only begin
@static if is_apple()
using Homebrew
provides(Homebrew.HB, "postgresql", libpq, os=:Darwin)
end
Expand Down
12 changes: 5 additions & 7 deletions src/dbi_impl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ function checkerrclear(result::Ptr{PGresult})
end

escapeliteral(db::PostgresDatabaseHandle, value) = value
escapeliteral(db::PostgresDatabaseHandle, value::AbstractString) = escapeliteral(db, bytestring(value))

function escapeliteral(db::PostgresDatabaseHandle, value::Union{ASCIIString, UTF8String})
function escapeliteral(db::PostgresDatabaseHandle, value::String)
strptr = PQescapeLiteral(db.ptr, value, sizeof(value))
str = bytestring(strptr)
PQfreemem(strptr)
return str
end

function escapeidentifier(db::PostgresDatabaseHandle, value::Union{ASCIIString, UTF8String})
function escapeidentifier(db::PostgresDatabaseHandle, value::String)
strptr = PQescapeIdentifier(db.ptr, value, sizeof(value))
str = bytestring(strptr)
PQfreemem(strptr)
Expand All @@ -115,8 +114,7 @@ function checkcopyreturnval(db::PostgresDatabaseHandle, returnval::Int32)
end
end

function copy_from(db::PostgresDatabaseHandle, table::AbstractString,
filename::AbstractString, format::AbstractString)
function copy_from(db::PostgresDatabaseHandle, table::AbstractString, filename::AbstractString, format::AbstractString)
f = open(filename)
try
Base.run(db, string("COPY ", escapeidentifier(db, table), " FROM STDIN ", format))
Expand All @@ -138,7 +136,7 @@ function getparamtypes(result::Ptr{PGresult})
return @compat [pgtype(OID{Int(PQparamtype(result, i-1))}) for i = 1:nparams]
end

LIBC = @windows ? "msvcrt.dll" : :libc
LIBC = @static is_windows() ? "msvcrt.dll" : :libc
strlen(ptr::Ptr{UInt8}) = ccall((:strlen, LIBC), Csize_t, (Ptr{UInt8},), ptr)

function getparams!(ptrs::Vector{Ptr{UInt8}}, params, types, sizes, lengths::Vector{Int32}, nulls)
Expand Down Expand Up @@ -293,7 +291,7 @@ end
function DBI.fetchdf(result::PostgresResultHandle)
df = DataFrame()
for i = 0:(length(result.types)-1)
df[symbol(bytestring(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i)
df[Symbol(bytestring(PQfname(result.ptr, i)))] = unsafe_fetchcol_dataarray(result, i)
end

return df
Expand Down
2 changes: 1 addition & 1 deletion src/libpq_common.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
macro c(ret_type, func, arg_types, lib)
local args_in = Any[ symbol(string('a',x)) for x in 1:length(arg_types.args) ]
local args_in = Any[ Symbol(string('a',x)) for x in 1:length(arg_types.args) ]
quote
$(esc(func))($(args_in...)) = ccall( ($(string(func)), $(Expr(:quote, lib)) ),
$ret_type, $arg_types, $(args_in...) )
Expand Down
22 changes: 5 additions & 17 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ newpgtype(:int2, 21, (Int16,))
newpgtype(:float8, 701, (Float64,))
newpgtype(:float4, 700, (Float32,))
newpgtype(:bpchar, 1042, ())
newpgtype(:varchar, 1043, (ASCIIString,UTF8String))
newpgtype(:varchar, 1043, (String,String))
newpgtype(:text, 25, ())
newpgtype(:numeric, 1700, (BigInt,BigFloat))
newpgtype(:date, 1082, ())
Expand All @@ -50,8 +50,8 @@ newpgtype(:_int4, 1007, (Vector{Int32},))
newpgtype(:_int2, 1005, (Vector{Int16},))
newpgtype(:_float8, 1022, (Vector{Float64},))
newpgtype(:_float4, 1021, (Vector{Float32},))
newpgtype(:_varchar, 1015, (Vector{ASCIIString}, Vector{UTF8String}))
newpgtype(:_text, 1009, (Vector{ASCIIString}, Vector{UTF8String}))
newpgtype(:_varchar, 1015, (Vector{String}, Vector{String}))
newpgtype(:_text, 1009, (Vector{String}, Vector{String}))


typealias PGStringTypes Union{Type{PostgresType{:bpchar}},
Expand Down Expand Up @@ -151,10 +151,6 @@ function pgdata(::Type{PostgresType{:numeric}}, ptr::Ptr{UInt8}, data::Number)
ptr = storestring!(ptr, string(data))
end

function pgdata(::PGStringTypes, ptr::Ptr{UInt8}, data::ByteString)
ptr = storestring!(ptr, data)
end

function pgdata(::PGStringTypes, ptr::Ptr{UInt8}, data::AbstractString)
ptr = storestring!(ptr, bytestring(data))
end
Expand Down Expand Up @@ -212,19 +208,11 @@ function pgdata(::Type{PostgresType{:_float4}}, ptr::Ptr{UInt8}, data::Vector{Fl
ptr = storestring!(ptr, string("{", join(data, ','), "}"))
end

function pgdata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}, data::Vector{ASCIIString})
ptr = storestring!(ptr, string("{", join(data, ','), "}"))
end

function pgdata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}, data::Vector{UTF8String})
ptr = storestring!(ptr, string("{", join(data, ','), "}"))
end

function pgdata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}, data::Vector{ASCIIString})
function pgdata(::Type{PostgresType{:_varchar}}, ptr::Ptr{UInt8}, data::Vector{String})
ptr = storestring!(ptr, string("{", join(data, ','), "}"))
end

function pgdata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}, data::Vector{UTF8String})
function pgdata(::Type{PostgresType{:_text}}, ptr::Ptr{UInt8}, data::Vector{String})
ptr = storestring!(ptr, string("{", join(data, ','), "}"))
end

Expand Down
12 changes: 6 additions & 6 deletions test/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function test_connection()
@test conn.status == PostgreSQL.CONNECTION_OK
@test errcode(conn) == PostgreSQL.CONNECTION_OK
@test !conn.closed
@test bytestring(libpq.PQdb(conn.ptr)) == "julia_test"
@test bytestring(libpq.PQuser(conn.ptr)) == "postgres"
@test bytestring(libpq.PQport(conn.ptr)) == "5432"
@test unsafe_string(libpq.PQdb(conn.ptr)) == "julia_test"
@test unsafe_string(libpq.PQuser(conn.ptr)) == "postgres"
@test unsafe_string(libpq.PQport(conn.ptr)) == "5432"

disconnect(conn)
@test conn.closed
Expand All @@ -33,9 +33,9 @@ function test_connection()
@test conn.status == PostgreSQL.CONNECTION_OK
@test errcode(conn) == PostgreSQL.CONNECTION_OK
@test !conn.closed
@test bytestring(libpq.PQdb(conn.ptr)) == "julia_test"
@test bytestring(libpq.PQuser(conn.ptr)) == "postgres"
@test bytestring(libpq.PQport(conn.ptr)) == "5432"
@test unsafe_string(libpq.PQdb(conn.ptr)) == "julia_test"
@test unsafe_string(libpq.PQuser(conn.ptr)) == "postgres"
@test unsafe_string(libpq.PQport(conn.ptr)) == "5432"

disconnect(conn)
@test conn.closed
Expand Down