Запрос SQLite работает на Android 4.4, но вылетает на Android 5.0 - PullRequest
0 голосов
/ 25 апреля 2018

Следующий запрос SQLite отлично работает на Android 4.4 и ниже, но вызывает исключение: «android.database.sqlite.SQLiteException: неоднозначное имя столбца: число (код 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 голосов
/ 25 апреля 2018
... 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 квалифицируются псевдонимом таблицы, кроме последнего. Это действительно неоднозначно.

...