1 26 27 package com.sqlmagic.tinysql; 28 29 import java.util.*; 30 import java.lang.*; 31 import java.io.*; 32 33 public class textFile extends tinySQL { 34 35 static String dataDir = System.getProperty("user.home") + "/.tinySQL"; 38 39 47 void CreateTable ( String table_name, Vector v ) 48 throws IOException, tinySQLException { 49 50 mkDataDirectory(); 53 54 DropTable(table_name); 57 58 FileOutputStream fdef = 61 new FileOutputStream( dataDir + "/" + table_name + ".def" ); 62 63 DataOutputStream def = new DataOutputStream (fdef); 66 67 def.writeBytes("CHAR|_DELETED|1\n"); 70 71 for (int i = 0; i < v.size(); i++) { 76 def.writeBytes( ((tsColumn) v.elementAt(i)).type + "|"); 77 def.writeBytes( ((tsColumn) v.elementAt(i)).name + "|"); 78 def.writeBytes( ((tsColumn) v.elementAt(i)).size + "\n"); 79 } 80 81 def.flush(); 84 85 fdef.close(); 88 } 89 90 98 tinySQLTable getTable (String table_name) throws tinySQLException { 99 return (tinySQLTable) new textFileTable (dataDir, table_name); 100 } 101 102 112 void AlterTableAddCol ( String table_name, Vector v ) 113 throws IOException, tinySQLException { 114 115 throw new tinySQLException("ALTER TABLE ADD is not supported"); 116 } 117 118 119 129 void AlterTableDropCol ( String table_name, Vector v ) 130 throws IOException, tinySQLException { 131 132 throw new tinySQLException("ALTER TABLE DROP is not supported"); 133 } 134 135 136 145 void DropTable (String fname) throws tinySQLException { 146 147 try { 148 149 Utils.delFile(dataDir, fname); 150 Utils.delFile(dataDir, fname + ".def"); 151 152 } catch (Exception e) { 153 throw new tinySQLException(e.getMessage()); 154 } 155 156 } 157 158 159 164 void mkDataDirectory() throws NullPointerException { 165 166 File dd = new File( dataDir ); 167 168 if (!dd.exists()) { 169 dd.mkdir(); 170 } 171 172 } 173 174 175 178 public static void main(String argv[]) { 179 } 202 } 203 204 | Popular Tags |