You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to do a join query and came across this bug, I'm doing someting like this:
on =SQLOn( SQLColumn("comments.user_id"), SQLColumn("users.id"))
j =Vector{SQLJoin}([
SQLJoin(Users.User, columns = [SQLColumn("users.name")], [on])
])
q =SQLQuery(where= [SQLWhereExpression("$(SQLColumn(:topic_id)) = ?", topic_id)], order =SQLOrder(:datetime, "DESC"))
DataFrame(Comments.Comment, q, j)
And I get an error telling me "comments.name" doesn't exists, while I asked for "users.name" in my query. The table_name is lost and replaced during the preparation of the query (in prepare_column_name).
The issue is that table_name that was already parsed in SQLColumn constructor is ignored here :
This fixes the issue, but seems a bit hacky. Not sure why we need to parse the column again, feels like that should be the job of the constructor.
@eval SearchLight beginfunctionprepare_column_name(column::SearchLight.SQLColumn, m::Type{T})::Stringwhere {T<:SearchLight.AbstractModel}
if column.raw
column.value |> string
else
column_data::Dict{Symbol,Any}= SearchLight.from_literal_column_name(column)
if!haskey(column_data, :table_name)
column_data[:table_name] = SearchLight.table(m)
endif!haskey(column_data, :alias)
column_data[:alias] =""endcolumn_data_to_column_name(column, column_data)
endendfunctionfrom_literal_column_name(column::SearchLight.SQLColumn)
c = column.value
result =Dict{Symbol,String}()
result[:original_string] = c
result[:table_name] = column.table_name
# has alias?ifoccursin(" AS ", c)
parts =split(c, " AS ")
result[:column_name] = parts[1]
result[:alias] = parts[2]
else
result[:column_name] = c
end# is fully qualified?ifoccursin(".", result[:column_name])
parts =split(result[:column_name], ".")
result[:table_name] = parts[1]
result[:column_name] = parts[2]
end
result
endend
SearchLightSQLite v2.2.1
The text was updated successfully, but these errors were encountered:
jonathanBieler
changed the title
SQLColumn table_name get lost when doing a Join operation
SQLColumn table_name get lost when doing a join operation
May 5, 2023
I was trying to do a join query and came across this bug, I'm doing someting like this:
And I get an error telling me "comments.name" doesn't exists, while I asked for "users.name" in my query. The
table_name
is lost and replaced during the preparation of the query (inprepare_column_name
).The issue is that
table_name
that was already parsed inSQLColumn
constructor is ignored here :SearchLight.jl/src/SearchLight.jl
Line 956 in 0b72060
This fixes the issue, but seems a bit hacky. Not sure why we need to parse the column again, feels like that should be the job of the constructor.
SearchLightSQLite v2.2.1
The text was updated successfully, but these errors were encountered: