SQLite查询适用于android 4.4,但在android 5.0上崩溃

时间:2018-04-25 12:58:36

标签: android sqlite android-sqlite android-5.0-lollipop android-compatibility

以下SQLite查询在Android 4.4及更低版本上运行正常,但它会导致异常:“android.database.sqlite.SQLiteException:ambiguous column name:number(code 1):......”在android 5.0上然后。我检查了SQLite发布文档,但没有看到任何可能影响我工作的更改。我有什么遗漏的东西吗?

select * from 
(
    select 
        '0' as queryid,
        CNCT._id,
        coalesce(case when length(C.abId)=0 then null else C.abId end, 
        (
            select  
                addrBkId  from numbers as nm, 
                contacts as cot 
            where nm.number=coalesce(C.number,S.Number) and nm.contactID = cot._id 
            order by cot.lastMod desc limit 1)) as addrBkId, 
        coalesce(
            case when length(C.abId)=0 then null else C.abId end, 
            (
                select  
                    addrBkId  from numbers as nm, 
                    contacts as cot 
                where nm.number=coalesce(C.number,S.Number) and nm.contactID = cot._id 
                order by cot.lastMod desc 
                limit 1
            )
        ) as uqAddrBkId,
        CNCT.displayName,
        CNCT.firstName,
        CNCT.lastName,
        CNCT.favorite,
        coalesce(C.location, 
        (
            select 
                location from calls as css 
            where css.number = S.Number
        )) as location,
        0 as numberType,
        coalesce(C.number,S.Number) number, 
        N.txt,A.type,
        coalesce(A.callID,A.smsId) actId,
        max(A.startEpoch) as maa,
        max(A.startTime),
        strftime('%w',datetime(A.startEpoch,'unixepoch','localtime'))+0 dayOfWeek, 
        strftime('%W',datetime(A.startEpoch,'unixepoch','localtime'))+0 weekOfYear,C.duration, 
        case 
            when C.callResult='vmail' then 'vmail'||C._id 
            when C.callType='callin' and C.callResult='missed' then 'missed' 
            else C.callType end as newCallType, 
        C.callResult,
        C.extension,
        C.msgId,
        C.audioUrl, 
        C.name, 
        C.state,
        C.syncParams, 
        S.smsId,
        S.dir,
        S.state, 
        N.noteId,
        N.color from activity as A 
    left outer join calls C on A.callId=C.callId 
    left outer join sms S on A.smsId=S.smsId 
    left outer join contacts CNCT on coalesce(case when length(C.abId)=0 then null else C.abId end, 
        (
            select  addrBkId  from numbers as nm, 
                contacts as cot 
            where nm.number=coalesce(C.number,S.Number) and nm.contactID = cot._id 
            order by cot.updated desc 
            limit 1)
        )=CNCT.addrBkId 
        left outer join 
        (
            select * from notes as nt 
            order by nt.lastMod asc
        ) as N on CNCT.addrBkId=N.addrBkId 
    where (C.state<>5 or C.state is NULL) and (C.callResult<>'abandoned' or C.callResult is NULL) 
    group by newCallType,number,weekOfYear,dayOfWeek 
    order by max(A.startEpoch) asc
) 
group by _id 
order by maa desc 
limit 3

1 个答案:

答案 0 :(得分:0)

... where nm.number=coalesce(C.number,S.Number) ...
... where nm.number=coalesce(C.number,S.Number) ...
... where css.number = S.Number) ...
... coalesce(C.number,S.Number) ...
... where nm.number=coalesce(C.number,S.Number) ...
... group by newCallType,number,...
                         ^^^^^^ 

number的所有出现都使用表别名限定,但最后一个除外。那个确实是模棱两可的。