Diciamo che ho un database SQLite che contiene una tabella:Perché scegliere 0, ... invece di SELEZIONE
sqlite> create table person (id integer, firstname varchar, lastname varchar);
Ora voglio ottenere ogni ingresso, che è nella tabella.
sqlite> select t0.id, t0.firstname, t0.lastname from person t0;
Questo funziona bene e questo è quello che vorrei usare. Tuttavia ho lavorato con un framework Apple (Core Data) che genera SQL. Questo quadro genera una leggermente diversa query SQL:
sqlite> select 0, t0.id, t0.firstname, t0.lastname from person t0;
interrogazione Ogni SQL generato da questo quadro inizia con "selezionare 0". Perché?
Ho provato a utilizzare il comando spiega per vedere che cosa sta succedendo, ma questo era inconcludente - almeno per me.
sqlite> explain select t0.id, t0.firstname, t0.lastname from person t0;
addr opcode p1 p2 p3 p4 p5 comment
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
0 Trace 0 0 0 00 NULL
1 Goto 0 11 0 00 NULL
2 OpenRead 0 2 0 3 00 NULL
3 Rewind 0 9 0 00 NULL
4 Column 0 0 1 00 NULL
5 Column 0 1 2 00 NULL
6 Column 0 2 3 00 NULL
7 ResultRow 1 3 0 00 NULL
8 Next 0 4 0 01 NULL
9 Close 0 0 0 00 NULL
10 Halt 0 0 0 00 NULL
11 Transactio 0 0 0 00 NULL
12 VerifyCook 0 1 0 00 NULL
13 TableLock 0 2 0 person 00 NULL
14 Goto 0 2 0 00 NULL
e il tavolo per la seconda query assomiglia a questo:
sqlite> explain select 0, t0.id, t0.firstname, t0.lastname from person t0;
addr opcode p1 p2 p3 p4 p5 comment
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
0 Trace 0 0 0 00 NULL
1 Goto 0 12 0 00 NULL
2 OpenRead 0 2 0 3 00 NULL
3 Rewind 0 10 0 00 NULL
4 Integer 0 1 0 00 NULL
5 Column 0 0 2 00 NULL
6 Column 0 1 3 00 NULL
7 Column 0 2 4 00 NULL
8 ResultRow 1 4 0 00 NULL
9 Next 0 4 0 01 NULL
10 Close 0 0 0 00 NULL
11 Halt 0 0 0 00 NULL
12 Transactio 0 0 0 00 NULL
13 VerifyCook 0 1 0 00 NULL
14 TableLock 0 2 0 person 00 NULL
15 Goto 0 2 0 00 NULL
Ma la costante '0 'è * non * dalla tabella B; è restituito incondizionatamente in ogni record di risultato. –
@CL. Modificato per rendere più chiaro cosa intendo. – hvd
Ma Core Data mette il '0' nella query più esterna. –