1 package com.quadcap.sql; 2 3 40 41 import java.util.Vector ; 42 43 import java.io.IOException ; 44 45 import java.sql.ResultSet ; 46 import java.sql.SQLException ; 47 48 import com.quadcap.sql.index.Btree; 49 50 import com.quadcap.util.Debug; 51 52 57 58 59 public class StmtDelete implements Stmt { 60 String tableName; 61 SelectExpression select; 62 63 66 public StmtDelete() {} 67 68 71 public StmtDelete(String tableName, Expression predicate) { 72 this.tableName = tableName; 73 this.select = new SelectExpression(tableName, predicate); 74 } 75 76 81 public void execute(Session session) throws IOException , SQLException { 82 try { 83 Database db = session.getDatabase(); 84 Relation t = db.getRelation(tableName); 85 if (t == null) { 86 throw new SQLException ("No such table/view: " + tableName, 87 "42000"); 88 } 89 if (!t.isUpdatable()) { 90 throw new SQLException ("Not updatable: " + tableName, 91 "42000"); 92 } 93 session.getTableWriteLock(tableName); 94 Cursor delCursor = select.getCursor(session, null); 95 try { 96 while (delCursor.next()) { 97 delCursor.deleteRow(); 98 } 99 } finally { 100 delCursor.close(); 101 } 102 } catch (IOException e) { 103 throw DbException.wrapThrowable(e); 104 } 105 106 } 107 } 108 109 110 | Popular Tags |