Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updating documentation, added getDriverVersion() to SQL

  • Loading branch information...
commit eec201557913592a2a6ed4ea059fae9175a547ab 1 parent 8a832a1
Florian Jenett authored
4 lib/build.number
View
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
-#Sun Dec 16 20:15:29 CET 2012
-build.number=544
+#Mon Dec 17 14:49:33 CET 2012
+build.number=553
2  release/BezierSQLib.txt
View
@@ -4,5 +4,5 @@ url = https://github.com/fjenett/sql-library-processing
category = DATA
sentence = A library to facilitate communication with SQL-based databases
paragraph = SQLibrary is an interface to MySQL, SQLite and PostgreSQL databases
-version = 1117
+version = 1126
prettyVersion = 0.2.0
BIN  release/BezierSQLib.zip
View
Binary file not shown
4 resources/build.number
View
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
-#Sun Dec 16 20:15:29 CET 2012
-build.number=1118
+#Mon Dec 17 14:49:38 CET 2012
+build.number=1134
2  src/de/bezier/data/sql/MySQL.java
View
@@ -4,7 +4,7 @@
import java.util.ArrayList;
/**
- * MySQL wrapper for SQL library for Processing 1+
+ * MySQL wrapper for SQL library for Processing 2+
* <p>
* A wrapper around some of sun's java.sql.* classes
* and the "com.mysql.jdbc.Driver" driver by mysql.com (GPL).
2  src/de/bezier/data/sql/PostgreSQL.java
View
@@ -4,7 +4,7 @@
import java.util.ArrayList;
/**
- * PostgreSQL wrapper for SQL library for Processing 1+
+ * PostgreSQL wrapper for SQL library for Processing 2+
* <p>
* This is a wrapper around some of sun's java.sql.* classes
* and the "org.postgresql.Driver" driver by postgresql.org (BSD).
196 src/de/bezier/data/sql/SQL.java
View
@@ -11,7 +11,7 @@
import java.util.ArrayList;
/**
- * <h1>SQL library for Processing 1+</h1>
+ * <h1>SQL library for Processing 2+</h1>
*
* Since v 0.2.0 it has some ORM like features, see
* <ul>
@@ -30,7 +30,7 @@
* @author Florian Jenett - mail@florianjenett.de
*
* created: 07.05.2005 - 12:46 Uhr
- * modified: fjenett 2012-02
+ * modified: fjenett 20121217
*/
abstract public class SQL
@@ -44,6 +44,9 @@
protected String pass;
public String driver = "";
public String type = "";
+
+ private int driverMinorVersion = -1;
+ private int driverMajorVersion = -1;
public java.sql.Connection connection;
public String previousQuery;
@@ -70,6 +73,7 @@ public SQL ()
mapper = new de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper();
}
+
/**
* You should not directly use the SQL.class instead use the classes for your database type.
*/
@@ -131,6 +135,7 @@ public SQL ( PApplet _pa, String _serv, String _db, String _u, String _p )
mapper = new de.bezier.data.sql.mapper.UnderScoreToCamelCaseMapper();
}
+
/**
* Turn some debugging on/off.
*
@@ -141,11 +146,18 @@ public void setDebug ( boolean yesNo )
DEBUG = yesNo;
}
+
+ /**
+ * Get current debugging setting
+ *
+ * @param yesNo Turn it on or off
+ */
public boolean getDebug ()
{
return DEBUG;
}
+
/**
* Open the database connection with the parameters given in the contructor.
*/
@@ -183,15 +195,46 @@ public boolean connect()
}
getTableNames();
+
+ try {
+ Driver jdbcDriver = java.sql.DriverManager.getDriver( url );
+ if ( jdbcDriver != null ) {
+ driverMinorVersion = jdbcDriver.getMinorVersion();
+ driverMajorVersion = jdbcDriver.getMajorVersion();
+
+ if ( DEBUG ) System.out.println( "Using driver " + getDriverVersion() );
+ }
+ } catch ( SQLException sqle ) {
+ sqle.printStackTrace();
+ }
return true;
}
+
+
+ /**
+ * Return the version of the currently active JDBC driver
+ *
+ * @return String The version of the current driver
+ */
+ public String getDriverVersion ()
+ {
+ if ( connection == null ) {
+ System.out.println( "SQL.getDriverVersion(): you need to connect() first" );
+ return null;
+ } else if ( driver == null || driver.equals("") ) {
+ System.out.println( "SQL.getDriverVersion(): no driver specified ... or it is null" );
+ return null;
+ }
+ return driver + " " + driverMajorVersion + "." + driverMinorVersion;
+ }
private void preQueryOrExecute ()
{
result = null;
}
+
/**
* Execute a SQL command on the open database connection.
*
@@ -204,6 +247,7 @@ public void execute ( String _sql )
query( _sql, false );
}
+
/**
* Execute a SQL command on the open database connection.
* Arguments are passed to String.format() first.
@@ -285,7 +329,7 @@ public void query ( String _sql, Object ... args )
ex.printStackTrace();
return;
}
-
+
String sql2 = null;
try {
sql2 = (String)meth.invoke( null, _sql, args );
@@ -296,6 +340,7 @@ public void query ( String _sql, Object ... args )
queryOrExecute( sql2, true );
}
+
/**
* Query implemenbtation called by execute() / query()
*/
@@ -333,6 +378,7 @@ private void queryOrExecute ( String _sql, boolean keep )
}
}
+
/**
* Check if more results (rows) are available. This needs to be called before any results can be retrieved.
*
@@ -353,11 +399,12 @@ public boolean next ()
catch ( java.sql.SQLException e )
{
System.out.println( "SQL.next(): java.sql.SQLException.\r" );
- if (DEBUG) e.printStackTrace();
+ if ( DEBUG ) e.printStackTrace();
}
return false;
}
+
/**
* Get names of available tables in active database,
* needs to be implemented per db adapter.
@@ -366,6 +413,7 @@ public boolean next ()
*/
abstract public String[] getTableNames ();
+
/**
* Returns an array with the column names of the last request.
*
@@ -415,6 +463,7 @@ public boolean next ()
return colNames;
}
+
/**
* Get connection. ... in case you want to do JDBC stuff directly.
*
@@ -425,6 +474,7 @@ public boolean next ()
return connection;
}
+
/**
* Read an integer value from the specified field.
* Represents an INT / INTEGER type:
@@ -457,7 +507,15 @@ public int getInt ( String _field )
return 0;
}
-
+ /**
+ * Read an integer value from the specified field.
+ * Represents an INT / INTEGER type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field to read
+ * @return int Value of the field or 0
+ */
public int getInt ( int _column )
{
if ( result == null )
@@ -478,6 +536,7 @@ public int getInt ( int _column )
return 0;
}
+
/**
* Read a long value from the specified field.
* Represents a BIGINT type:
@@ -507,6 +566,16 @@ public long getLong ( String _field )
return 0;
}
+
+ /**
+ * Read a long value from the specified field.
+ * Represents a BIGINT type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return long Value of the field or 0
+ */
public long getLong ( int _column )
{
if ( result == null )
@@ -527,6 +596,7 @@ public long getLong ( int _column )
return 0;
}
+
/**
* Read a float value from the specified field.
* Represents a REAL type:
@@ -555,7 +625,17 @@ public float getFloat ( String _field )
}
return 0.0f;
}
-
+
+
+ /**
+ * Read a float value from the specified field.
+ * Represents a REAL type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The index of the column of the field
+ * @return float Value of the field or 0
+ */
public float getFloat ( int _column )
{
if ( result == null )
@@ -605,7 +685,17 @@ public double getDouble ( String _field )
}
return 0.0;
}
-
+
+
+ /**
+ * Read a double value from the specified field.
+ * Represents FLOAT and DOUBLE types:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return double Value of the field or 0
+ */
public double getDouble ( int _column )
{
if ( result == null )
@@ -655,7 +745,17 @@ public double getDouble ( int _column )
}
return null;
}
-
+
+
+ /**
+ * Read a java.math.BigDecimal value from the specified field.
+ * Represents DECIMAL and NUMERIC types:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return java.math.BigDecimal Value of the field or null
+ */
public java.math.BigDecimal getBigDecimal ( int _column )
{
if ( result == null )
@@ -706,6 +806,16 @@ public boolean getBoolean ( String _field )
return false;
}
+
+ /**
+ * Read a boolean value from the specified field.
+ * Represents BIT type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return boolean Value of the field or 0
+ */
public boolean getBoolean ( int _column )
{
if ( result == null )
@@ -755,7 +865,16 @@ public String getString ( String _field )
}
return null;
}
-
+
+ /**
+ * Read a String value from the specified field.
+ * Represents VARCHAR and CHAR types:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return String Value of the field or null
+ */
public String getString ( int _column )
{
if ( result == null )
@@ -776,7 +895,6 @@ public String getString ( int _column )
return null;
}
-
/**
* Read a java.sql.Date value from the specified field.
* Represents DATE type:
@@ -806,6 +924,16 @@ public String getString ( int _column )
return null;
}
+
+ /**
+ * Read a java.sql.Date value from the specified field.
+ * Represents DATE type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return java.sql.Date Value of the field or null
+ */
public java.sql.Date getDate ( int _column )
{
if ( result == null )
@@ -856,6 +984,16 @@ public String getString ( int _column )
return null;
}
+
+ /**
+ * Read a java.sql.Time value from the specified field.
+ * Represents TIME type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return java.sql.Time Value of the field or null
+ */
public java.sql.Time getTime ( int _column )
{
if ( result == null )
@@ -906,6 +1044,16 @@ public String getString ( int _column )
return null;
}
+
+ /**
+ * Read a java.sql.Timestamp value from the specified field.
+ * Represents TIMESTAMP type:
+ * http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html
+ * "8.9.6 Conversions by ResultSet.getXXX Methods"
+ *
+ * @param _column The column index of the field
+ * @return java.sql.Timestamp Value of the field or null
+ */
public java.sql.Timestamp getTimestamp ( int _column )
{
if ( result == null )
@@ -953,6 +1101,13 @@ public Object getObject ( String _field )
return null;
}
+
+ /**
+ * Read a value from the specified field to hav it returned as an object.
+ *
+ * @param _column The column index of the field
+ * @return Object Value of the field or null
+ */
public Object getObject ( int _column )
{
if ( result == null )
@@ -973,6 +1128,7 @@ public Object getObject ( int _column )
return null;
}
+
/**
* Close the database connection
*/
@@ -984,6 +1140,8 @@ public void close()
/**
* Callback function for PApplet.registerDispose()
+ *
+ * @see processing.core.PApplet.registerDispose(java.lang.Object)
*/
public void dispose ()
{
@@ -1021,15 +1179,19 @@ public void dispose ()
}
}
-
+
/**
- * Escape ...
+ * Generate an escaped String for a given Object
+ *
+ * @param object the Object to escape
+ * @return String the ecaped String representation of the Object
*/
public String escape ( Object o )
{
- return "\"" + o + "\"";
+ return "\"" + o.toString().replaceAll("\"","\\\"") + "\"";
}
+
/**
* Set the current NameMapper
*
@@ -1041,6 +1203,7 @@ public void setNameMapper ( NameMapper mapper )
this.mapper = mapper;
}
+
/**
* Get the current NameMapper
*
@@ -1051,6 +1214,7 @@ public NameMapper getNameMapper ()
return mapper;
}
+
/**
* <p>Highly experimental ...<br />
* tries to map column names to public fields or setter methods
@@ -1129,6 +1293,7 @@ public void setFromRow ( Object object )
}
}
+
/**
* Convert a field name to a setter name: fieldName -> setFieldName().
*/
@@ -1139,6 +1304,7 @@ public String nameToSetter ( String name )
return "set" + name.substring(0,1).toUpperCase() + name.substring(1);
}
+
/**
* Convert a field name to a getter name: fieldName -> getFieldName().
*/
@@ -1149,6 +1315,7 @@ public String nameToGetter ( String name )
return "get" + name.substring(0,1).toUpperCase() + name.substring(1);
}
+
/**
* Set a table name for a class.
*/
@@ -1171,6 +1338,7 @@ public void registerTableNameForClass ( String name, Object classOrObject )
));
}
+
/**
* Take an object, try to find table name from object name (or look it up),
* get fields and getters from object and pass that on to
@@ -1218,6 +1386,7 @@ public void saveToDatabase ( Object object )
}
}
+
/**
* Takes a table name and an object and tries to construct a set of
* columns names from fields and getters found in the object. After
@@ -1348,6 +1517,7 @@ public void saveToDatabase ( String tableName, Object object )
}
}
+
/**
* Insert or update a bunch of values in the database. If the given table has a
* primary key the entry will be updated if it already existed.
10 src/de/bezier/data/sql/SQLite.java
View
@@ -4,14 +4,14 @@
import java.util.ArrayList;
/**
- * SQLite wrapper for SQL library for Processing 1+
+ * SQLite wrapper for SQL library for Processing 2+
* <p>
* A wrapper around some of sun's java.sql.* classes
- * and the pure java "org.sqlite.JDBC" driver by zentus.com (BSD).
+ * and the pure java "org.sqlite.JDBC" driver of the Xerial project (Apache 2 license).
* </p>
* see:<ul>
- * <li>http://www.zentus.com/sqlitejdbc/</li>
- * <li>http://files.zentus.com/sqlitejdbc/</li>
+ * <li>http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC</li>
+ * <li>http://www.xerial.org/maven/repository/site/xerial-project/sqlite-jdbc/apidocs/index.html?index-all.html</li>
* <li>http://java.sun.com/products/jdbc/</li>
* </ul>
*
@@ -19,7 +19,7 @@
* @author Florian Jenett - mail@florianjenett.de
*
* created: 2008-11-29 12:15:15 - fjenett
- * modified: 2012-02
+ * modified: fjenett 20121217
*
*/
Please sign in to comment.
Something went wrong with that request. Please try again.