Come inserire bulk con SQLite?Come inserire bulk con SQLite?
L'ho cercato e mi sembra di inserire un inserto con un'istruzione select. Ho cercato su Google, ho esaminato gli esempi e sembrano tutti copiati da una tabella a un'altra o non sono compatibili con SQLite. Voglio fare qualcosa di simile
"INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_media_date) " +
"VALUES(@mediaId, @catagory, @current_media_date)";
where the value of recipientId is the watcher from each of
"SELECT watcher FROM userwatch WHERE [email protected]";
Ho provato il codice qui sotto e ottengo l'errore "errore di SQLite tale colonna: watcher"
command.CommandText =
"CREATE TABLE if not exists user_msg_media(" +
"msgId INTEGER PRIMARY KEY, " +
"recipientId INTEGER, " +
"mediaId INTEGER, " +
"catagory INTEGER, " +
"current_date DATE);";
command.ExecuteNonQuery();
//user media
command.CommandText =
"CREATE TABLE if not exists user_watch(" +
"indx INTEGER PRIMARY KEY, " +
"watcher INTEGER, " +
"watched INTEGER);";
command.ExecuteNonQuery();
//...
command.CommandText = "SELECT watcher FROM user_watch WHERE watched=:watched;";
command.Parameters.Add(":watched", DbType.Int64).Value = 1;
command.ExecuteNonQuery(); //is ok
command.CommandText =
"INSERT INTO user_msg_media (recipientId, mediaId, catagory, current_media_date) " +
"SELECT watcher, :mediaId, :category, :current_media_date" +
"FROM user_watch WHERE watched=:watched;";
command.Parameters.Add(":mediaId", DbType.Int64).Value = 0;
command.Parameters.Add(":category", DbType.Int64).Value = 0;
command.Parameters.Add(":current_media_date", DbType.Int64).Value = 0;
command.Parameters.Add(":watched", DbType.Int64).Value = 1;
command.ExecuteNonQuery();
Si sta utilizzando System.Data.Sqlite? –
Nota la tabella CREATE per usr_msg_media rende una colonna denominata current_date, ma l'INSERT prova a impostare current_media_date invece: Credo che questo errore sia stato diagnosticato erroneamente da SQLite (si confonde e afferma che la colonna mancante è watcher), poiché posso riprodurre messaggio di errore errato - ma se risolvo l'errore effettivo, funziona, vedi il codice di esempio Python nella mia risposta. –