-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jdbc): DatabaseMetaData.getTypeInfo() returns more accurate values
relates to #786
- Loading branch information
Showing
3 changed files
with
288 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.sqlite.util; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class QueryUtils { | ||
/** | ||
* Build a SQLite query using the VALUES clause to return arbitrary values. | ||
* | ||
* @param columns list of column names | ||
* @param valuesList values to return as rows | ||
* @return SQL query as string | ||
*/ | ||
public static String valuesQuery(List<String> columns, List<List<Object>> valuesList) { | ||
valuesList.forEach( | ||
(list) -> { | ||
if (list.size() != columns.size()) | ||
throw new IllegalArgumentException( | ||
"values and columns must have the same size"); | ||
}); | ||
return "with cte(" | ||
+ String.join(",", columns) | ||
+ ") as (values " | ||
+ valuesList.stream() | ||
.map( | ||
(values) -> | ||
"(" | ||
+ values.stream() | ||
.map( | ||
(o -> { | ||
if (o instanceof String) | ||
return "'" + o + "'"; | ||
if (o == null) return "null"; | ||
return o.toString(); | ||
})) | ||
.collect(Collectors.joining(",")) | ||
+ ")") | ||
.collect(Collectors.joining(",")) | ||
+ ") select * from cte"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters