Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2008
    Messaggi
    813

    [java] sqlite drop table

    ciao a tutti,
    devo fare un piccolo travaso da una tabella ad un altra, con la successiva cancellazione della prima tabella.
    Sto usando sqlite come dbms e uso queste istruzioni

    codice:
    String tmpName="__tmp_wb_item_table__";
    PreparedStatement alterTable = conn.prepareStatement("ALTER TABLE `t1` RENAME TO `"+tmpName+"`;");
    alterTable.close();
    			
    			
    install();
    			
    PreparedStatement insert = conn.prepareStatement("INSERT INTO `t1` (`wid`,`iid`,`qty`,`price`,`vat`) " +
    					"SELECT `wid`,`iid`,`qty`,`price`,`vat` FROM `"+tmpName+"`");
    			
    insert.executeUpdate();
    insert.close();
    						
    PreparedStatement deleteTable = conn.prepareStatement("DROP TABLE `"+tmpName+"`");
    deleteTable.executeUpdate();	
    deleteTable.close();
    il problema e che non riesco ad eseguire il drop alla fine, perché mi dice:

    [SQLITE_LOCKED] A table in the database is locked (database table is locked)

    non so proprio cosa fare...
    ho provato di tutto, ma il problema rimane.
    Sembra che quell'alter table metta un lock sulla tabella (perché prima ho provato a fare alter e drop) e non riesco ad effettuare la cancellazione.
    C'è un modo per risolvere questo problema?
    vi ringrazio anticipatamente
    Nell'anno 1968 è bastata la potenza di due Commodore 64 per lanciare con successo una navicella sulla Luna; nell'anno 2007 ci vogliono la potenza di un processore quad core 3.30 GHz e 3 Gb di RAM (requisiti minimi ufficiali) per utilizzare Windows Vista. Qualcosa deve essere andato storto!

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    non ti seguo:

    - rinomini T1 in __tmp_wb_item_table__
    - provi a fare una INSERT su T1 che non esiste più
    - cancelli __tmp_wb_item_table__

    sicuro che non si blocchi alla insert?

    Dalle FAQs di SQLite: http://www.sqlite.org/faq.html (11)
    (11) How do I add or delete columns from an existing table in SQLite.


    SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.

    For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done:

    BEGIN TRANSACTION;
    CREATE TEMPORARY TABLE t1_backup(a,b);
    INSERT INTO t1_backup SELECT a,b FROM t1;
    DROP TABLE t1;
    CREATE TABLE t1(a,b);
    INSERT INTO t1 SELECT a,b FROM t1_backup;
    DROP TABLE t1_backup;
    COMMIT;
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2011
    Messaggi
    147
    A parte quanto detto già da Andrea e a parte che la sintassi della insert nella query nidificata è errata, rinominare solo le tabelle no??

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.