diff --git a/deps/build.jl b/deps/build.jl index e75a4fb..3e8f08d 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -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 diff --git a/src/dbi_impl.jl b/src/dbi_impl.jl index 6c68149..47f09a1 100644 --- a/src/dbi_impl.jl +++ b/src/dbi_impl.jl @@ -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) @@ -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)) @@ -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) @@ -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 diff --git a/src/libpq_common.jl b/src/libpq_common.jl index 117808b..02fe849 100644 --- a/src/libpq_common.jl +++ b/src/libpq_common.jl @@ -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...) ) diff --git a/src/types.jl b/src/types.jl index 599d396..7d4f0f3 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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, ()) @@ -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}}, @@ -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 @@ -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 diff --git a/test/connection.jl b/test/connection.jl index 89e8162..74dd9d3 100644 --- a/test/connection.jl +++ b/test/connection.jl @@ -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 @@ -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