Home | History | Annotate | Download | only in SQLite
      1 package SQLite;
      2 
      3 import java.sql.*;
      4 import java.util.Properties;
      5 
      6 public class JDBCDriver implements java.sql.Driver {
      7 
      8     public static final int MAJORVERSION = 1;
      9 
     10     public static boolean sharedCache = false;
     11 
     12     public static String vfs = null;
     13 
     14     private static java.lang.reflect.Constructor makeConn = null;
     15 
     16     protected Connection conn;
     17 
     18     static {
     19 	try {
     20 	    Class connClass = null;
     21 	    Class args[] = new Class[5];
     22 	    args[0] = Class.forName("java.lang.String");
     23 	    args[1] = args[0];
     24 	    args[2] = args[0];
     25 	    args[3] = args[0];
     26 	    args[4] = args[0];
     27 	    String jvers = java.lang.System.getProperty("java.version");
     28 	    String cvers;
     29 	    if (jvers == null || jvers.startsWith("1.0")) {
     30 		throw new java.lang.Exception("unsupported java version");
     31 	    } else if (jvers.startsWith("1.1")) {
     32 		cvers = "SQLite.JDBC1.JDBCConnection";
     33 	    } else if (jvers.startsWith("1.2") || jvers.startsWith("1.3")) {
     34 		cvers = "SQLite.JDBC2.JDBCConnection";
     35 	    } else if (jvers.startsWith("1.4")) {
     36 		cvers = "SQLite.JDBC2x.JDBCConnection";
     37 	    } else if (jvers.startsWith("1.5")) {
     38 		cvers = "SQLite.JDBC2y.JDBCConnection";
     39 		try {
     40 		    Class.forName(cvers);
     41 		} catch (java.lang.Exception e) {
     42 		    cvers = "SQLite.JDBC2x.JDBCConnection";
     43 		}
     44 	    } else {
     45 		cvers = "SQLite.JDBC2z.JDBCConnection";
     46 		try {
     47 		    Class.forName(cvers);
     48 		} catch (java.lang.Exception e) {
     49 		    cvers = "SQLite.JDBC2y.JDBCConnection";
     50 		    try {
     51 			Class.forName(cvers);
     52 		    } catch (java.lang.Exception ee) {
     53 			cvers = "SQLite.JDBC2x.JDBCConnection";
     54 		    }
     55 		}
     56 	    }
     57 	    connClass = Class.forName(cvers);
     58 	    makeConn = connClass.getConstructor(args);
     59 	    java.sql.DriverManager.registerDriver(new JDBCDriver());
     60 	    try {
     61 		String shcache =
     62 		    java.lang.System.getProperty("SQLite.sharedcache");
     63 		if (shcache != null &&
     64 		    (shcache.startsWith("y") || shcache.startsWith("Y"))) {
     65 		    sharedCache = SQLite.Database._enable_shared_cache(true);
     66 		}
     67 	    } catch (java.lang.Exception e) {
     68 	    }
     69 	    try {
     70 		String tvfs =
     71 		    java.lang.System.getProperty("SQLite.vfs");
     72 		if (tvfs != null) {
     73 		    vfs = tvfs;
     74 		}
     75 	    } catch (java.lang.Exception e) {
     76 	    }
     77 	} catch (java.lang.Exception e) {
     78 	    System.err.println(e);
     79 	}
     80     }
     81 
     82     public JDBCDriver() {
     83     }
     84 
     85     public boolean acceptsURL(String url) throws SQLException {
     86 	return url.startsWith("sqlite:/") ||
     87 	    url.startsWith("jdbc:sqlite:/");
     88     }
     89 
     90     public Connection connect(String url, Properties info)
     91 	throws SQLException {
     92 	if (!acceptsURL(url)) {
     93 	    return null;
     94 	}
     95 	Object args[] = new Object[5];
     96 	args[0] = url;
     97 	if (info != null) {
     98 	    args[1] = info.getProperty("encoding");
     99 	    args[2] = info.getProperty("password");
    100 	    args[3] = info.getProperty("daterepr");
    101 	    args[4] = info.getProperty("vfs");
    102 	}
    103 	if (args[1] == null) {
    104 	    args[1] = java.lang.System.getProperty("SQLite.encoding");
    105 	}
    106 	if (args[4] == null) {
    107 	    args[4] = vfs;
    108 	}
    109 	try {
    110 	    conn = (Connection) makeConn.newInstance(args);
    111 	} catch (java.lang.reflect.InvocationTargetException ie) {
    112 	    throw new SQLException(ie.getTargetException().toString());
    113 	} catch (java.lang.Exception e) {
    114 	    throw new SQLException(e.toString());
    115 	}
    116 	return conn;
    117     }
    118 
    119     public int getMajorVersion() {
    120 	return MAJORVERSION;
    121     }
    122 
    123     public int getMinorVersion() {
    124 	return Constants.drv_minor;
    125     }
    126 
    127     public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
    128 	throws SQLException {
    129 	DriverPropertyInfo p[] = new DriverPropertyInfo[4];
    130 	DriverPropertyInfo pp = new DriverPropertyInfo("encoding", "");
    131 	p[0] = pp;
    132 	pp = new DriverPropertyInfo("password", "");
    133 	p[1] = pp;
    134 	pp = new DriverPropertyInfo("daterepr", "normal");
    135 	p[2] = pp;
    136 	pp = new DriverPropertyInfo("vfs", vfs);
    137 	p[3] = pp;
    138 	return p;
    139     }
    140 
    141     public boolean jdbcCompliant() {
    142 	return false;
    143     }
    144 }
    145