tags:

views:

83

answers:

4

I want to do something like this

INSERT INTO link_list(link, status, hash_type, hash_id)
VALUES(@link, @status, @hash_type, @hash_id);
INSERT INTO active_dl(fileId, orderNo)
VALUES(last_insert_rowid(), SELECT COUNT(*) FROM active_dl);

But obviously it is wrong and theres a syntax error on select. How do i write this? Using sqlite.

+1  A: 

Put the SELECT query in brackets parenthesis.

Like so:

INSERT INTO active_dl(fileId, orderNo)
VALUES(last_insert_rowid(), (SELECT COUNT(*) FROM active_dl));
Franz
A: 

Why don't you try:

DECLARE @var INT
SET @var = (Select Count(*) from active_dl)

INSERT INTO active_dl(fileId, orderNo)
VALUES(last_insert_rowid(), @var);
Jack Marchetti
A: 

have you tried maybe:

...
VALUES(last_insert_rowid(), (SELECT COUNT(*) FROM active_dl)); <--- with parens

I don't claim to know sqlite, but maybe this could help

Jason
A: 

I believe standard SQL lets you use either values or select for an insert, so I'd be looking at:

insert into active_dl(fileId, orderNo)
    select last_insert_rowid(), COUNT(*) FROM active_dl;

Whether SQLite allows this I don't know for sure, hence the community wiki.

paxdiablo