Package org.sqlite
Class Collation
java.lang.Object
org.sqlite.Collation
Provides an interface for creating SQLite user-defined collations.
A subclass of org.sqlite.Collation can be registered with Collation.create() and called by the name it was given. All collations must implement xCompare(String, String), which is called when SQLite compares two strings using the custom collation. Eg.
Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:"); Collation.create(conn, "REVERSE", new Collation() { protected int xCompare(String str1, String str2) { return str1.compareTo(str2) * -1; } }); conn.createStatement().execute("select c1 from t order by c1 collate REVERSE;");
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final void
create
(Connection conn, String name, Collation f) Registers a given collation with the connection.static final void
destroy
(Connection conn, String name) Removes a named collation from the given connection.protected abstract int
Called by SQLite as a custom collation to compare two strings.
-
Constructor Details
-
Collation
public Collation()
-
-
Method Details
-
create
Registers a given collation with the connection.- Parameters:
conn
- The connection.name
- The name of the collation.f
- The collation to register.- Throws:
SQLException
-
destroy
Removes a named collation from the given connection.- Parameters:
conn
- The connection to remove the collation from.name
- The name of the collation.- Throws:
SQLException
-
xCompare
Called by SQLite as a custom collation to compare two strings.- Parameters:
str1
- the first string in the comparisonstr2
- the second string in the comparison- Returns:
- an integer that is negative, zero, or positive if the first string is less than, equal to, or greater than the second, respectively
-