Skip to content

Commit 4cc5999

Browse files
committed
Use an empty DataFrame when there is no data available
1 parent 8989864 commit 4cc5999

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/SQLite.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ module SQLite
22

33
using DataFrames
44

5-
export sqlitedb, readdlmsql, query, connect, createtable, droptable
5+
export sqlitedb, readdlmsql, query, createtable, droptable
6+
7+
import Base: show
68

79
include("SQLite_consts.jl")
810
include("SQLite_api.jl")
@@ -69,8 +71,7 @@ function internal_query(conn::SQLiteDB,q::String,finalize::Bool=true,stepped::Bo
6971
end
7072
function query(q::String,conn::SQLiteDB=sqlitedb)
7173
conn == null_SQLiteDB && error("[sqlite]: A valid SQLiteDB was not specified (and no valid default SQLiteDB exists)")
72-
stmt, r = SQLite.internal_query(conn,q,false)
73-
r == SQLITE_DONE && return DataFrame("No Rows Returned")
74+
stmt, status = SQLite.internal_query(conn,q,false)
7475
#get resultset metadata: column count, column types, and column names
7576
ncols = SQLite.sqlite3_column_count(stmt)
7677
colnames = Array(UTF8String,ncols)
@@ -93,7 +94,7 @@ function query(q::String,conn::SQLiteDB=sqlitedb)
9394
end
9495
end
9596
#retrieve resultset
96-
while true
97+
while status != SQLITE_DONE
9798
for i = 1:ncols
9899
t = SQLite.sqlite3_column_type(stmt,i-1)
99100
if t == SQLITE3_TEXT
@@ -107,13 +108,13 @@ function query(q::String,conn::SQLiteDB=sqlitedb)
107108
end
108109
push!(resultset[i],r)
109110
end
110-
sqlite3_step(stmt) == SQLITE_DONE && break
111+
status = sqlite3_step(stmt)
111112
end
112113
#this is for columns we couldn't get the type for earlier (NULL in row 1); should be the exception
113114
if check != ncols
114115
nrows = length(resultset[1])
115116
for i = 1:ncols
116-
if isna(resultset[i][1])
117+
if nrows > 0 && isna(resultset[i][1])
117118
d = resultset[i]
118119
for j = 2:nrows
119120
if !isna(d[j])

0 commit comments

Comments
 (0)