1+ package com .boylegu .springboot_vue .config ;
2+
3+ /*
4+ * The author disclaims copyright to this source code. In place of
5+ * a legal notice, here is a blessing:
6+ *
7+ * May you do good and not evil.
8+ * May you find forgiveness for yourself and forgive others.
9+ * May you share freely, never taking more than you give.
10+ *
11+ */
12+
13+ import java .sql .Types ;
14+ import org .hibernate .dialect .Dialect ;
15+
16+ import org .hibernate .dialect .function .AbstractAnsiTrimEmulationFunction ;
17+ import org .hibernate .dialect .function .NoArgSQLFunction ;
18+ import org .hibernate .dialect .function .SQLFunction ;
19+ import org .hibernate .dialect .function .SQLFunctionTemplate ;
20+ import org .hibernate .dialect .function .StandardSQLFunction ;
21+ import org .hibernate .dialect .function .VarArgsSQLFunction ;
22+ import org .hibernate .type .StandardBasicTypes ;
23+
24+ public class SQLiteDialect extends Dialect {
25+ public SQLiteDialect () {
26+ registerColumnType (Types .BIT , "boolean" );
27+ registerColumnType (Types .TINYINT , "tinyint" );
28+ registerColumnType (Types .SMALLINT , "smallint" );
29+ registerColumnType (Types .INTEGER , "integer" );
30+ registerColumnType (Types .BIGINT , "bigint" );
31+ registerColumnType (Types .FLOAT , "float" );
32+ registerColumnType (Types .REAL , "real" );
33+ registerColumnType (Types .DOUBLE , "double" );
34+ registerColumnType (Types .NUMERIC , "numeric($p, $s)" );
35+ registerColumnType (Types .DECIMAL , "decimal" );
36+ registerColumnType (Types .CHAR , "char" );
37+ registerColumnType (Types .VARCHAR , "varchar($l)" );
38+ registerColumnType (Types .LONGVARCHAR , "longvarchar" );
39+ registerColumnType (Types .DATE , "date" );
40+ registerColumnType (Types .TIME , "time" );
41+ registerColumnType (Types .TIMESTAMP , "datetime" );
42+ registerColumnType (Types .BINARY , "blob" );
43+ registerColumnType (Types .VARBINARY , "blob" );
44+ registerColumnType (Types .LONGVARBINARY , "blob" );
45+ registerColumnType (Types .BLOB , "blob" );
46+ registerColumnType (Types .CLOB , "clob" );
47+ registerColumnType (Types .BOOLEAN , "boolean" );
48+
49+ //registerFunction( "abs", new StandardSQLFunction("abs") );
50+ registerFunction ( "concat" , new VarArgsSQLFunction (StandardBasicTypes .STRING , "" , "||" , "" ) );
51+ //registerFunction( "length", new StandardSQLFunction("length", StandardBasicTypes.LONG) );
52+ //registerFunction( "lower", new StandardSQLFunction("lower") );
53+ registerFunction ( "mod" , new SQLFunctionTemplate (StandardBasicTypes .INTEGER , "?1 % ?2" ) );
54+ registerFunction ( "quote" , new StandardSQLFunction ("quote" , StandardBasicTypes .STRING ) );
55+ registerFunction ( "random" , new NoArgSQLFunction ("random" , StandardBasicTypes .INTEGER ) );
56+ registerFunction ( "round" , new StandardSQLFunction ("round" ) );
57+ registerFunction ( "substr" , new StandardSQLFunction ("substr" , StandardBasicTypes .STRING ) );
58+ registerFunction ( "substring" , new SQLFunctionTemplate ( StandardBasicTypes .STRING , "substr(?1, ?2, ?3)" ) );
59+ registerFunction ( "trim" , new AbstractAnsiTrimEmulationFunction () {
60+ protected SQLFunction resolveBothSpaceTrimFunction () {
61+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "trim(?1)" );
62+ }
63+
64+ protected SQLFunction resolveBothSpaceTrimFromFunction () {
65+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "trim(?2)" );
66+ }
67+
68+ protected SQLFunction resolveLeadingSpaceTrimFunction () {
69+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "ltrim(?1)" );
70+ }
71+
72+ protected SQLFunction resolveTrailingSpaceTrimFunction () {
73+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "rtrim(?1)" );
74+ }
75+
76+ protected SQLFunction resolveBothTrimFunction () {
77+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "trim(?1, ?2)" );
78+ }
79+
80+ protected SQLFunction resolveLeadingTrimFunction () {
81+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "ltrim(?1, ?2)" );
82+ }
83+
84+ protected SQLFunction resolveTrailingTrimFunction () {
85+ return new SQLFunctionTemplate (StandardBasicTypes .STRING , "rtrim(?1, ?2)" );
86+ }
87+ } );
88+ //registerFunction( "upper", new StandardSQLFunction("upper") );
89+ }
90+
91+ public boolean supportsIdentityColumns () {
92+ return true ;
93+ }
94+
95+ /*
96+ public boolean supportsInsertSelectIdentity() {
97+ return true; // As specify in NHibernate dialect
98+ }
99+ */
100+
101+ public boolean hasDataTypeInIdentityColumn () {
102+ return false ; // As specify in NHibernate dialect
103+ }
104+
105+ /*
106+ public String appendIdentitySelectToInsert(String insertString) {
107+ return new StringBuffer(insertString.length()+30). // As specify in NHibernate dialect
108+ append(insertString).
109+ append("; ").append(getIdentitySelectString()).
110+ toString();
111+ }
112+ */
113+
114+ public String getIdentityColumnString () {
115+ // return "integer primary key autoincrement";
116+ return "integer" ;
117+ }
118+
119+ public String getIdentitySelectString () {
120+ return "select last_insert_rowid()" ;
121+ }
122+
123+ public boolean supportsLimit () {
124+ return true ;
125+ }
126+
127+ public boolean bindLimitParametersInReverseOrder () {
128+ return true ;
129+ }
130+
131+ protected String getLimitString (String query , boolean hasOffset ) {
132+ return new StringBuffer (query .length ()+20 ).
133+ append (query ).
134+ append (hasOffset ? " limit ? offset ?" : " limit ?" ).
135+ toString ();
136+ }
137+
138+ public boolean supportsTemporaryTables () {
139+ return true ;
140+ }
141+
142+ public String getCreateTemporaryTableString () {
143+ return "create temporary table if not exists" ;
144+ }
145+
146+ public boolean dropTemporaryTableAfterUse () {
147+ return true ; // TODO Validate
148+ }
149+
150+ public boolean supportsCurrentTimestampSelection () {
151+ return true ;
152+ }
153+
154+ public boolean isCurrentTimestampSelectStringCallable () {
155+ return false ;
156+ }
157+
158+ public String getCurrentTimestampSelectString () {
159+ return "select current_timestamp" ;
160+ }
161+
162+ public boolean supportsUnionAll () {
163+ return true ;
164+ }
165+
166+ public boolean hasAlterTable () {
167+ return false ; // As specify in NHibernate dialect
168+ }
169+
170+ public boolean dropConstraints () {
171+ return false ;
172+ }
173+
174+ /*
175+ public String getAddColumnString() {
176+ return "add column";
177+ }
178+ */
179+
180+ public String getForUpdateString () {
181+ return "" ;
182+ }
183+
184+ public boolean supportsOuterJoinForUpdate () {
185+ return false ;
186+ }
187+
188+ public String getDropForeignKeyString () {
189+ throw new UnsupportedOperationException ("No drop foreign key syntax supported by SQLiteDialect" );
190+ }
191+
192+ public String getAddForeignKeyConstraintString (String constraintName ,
193+ String [] foreignKey , String referencedTable , String [] primaryKey ,
194+ boolean referencesPrimaryKey ) {
195+ throw new UnsupportedOperationException ("No add foreign key syntax supported by SQLiteDialect" );
196+ }
197+
198+ public String getAddPrimaryKeyConstraintString (String constraintName ) {
199+ throw new UnsupportedOperationException ("No add primary key syntax supported by SQLiteDialect" );
200+ }
201+
202+ public boolean supportsIfExistsBeforeTableName () {
203+ return true ;
204+ }
205+
206+ public boolean supportsCascadeDelete () {
207+ return true ;
208+ }
209+
210+ /* not case insensitive for unicode characters by default (ICU extension needed)
211+ public boolean supportsCaseInsensitiveLike() {
212+ return true;
213+ }
214+ */
215+
216+ public boolean supportsTupleDistinctCounts () {
217+ return false ;
218+ }
219+
220+ public String getSelectGUIDString () {
221+ return "select hex(randomblob(16))" ;
222+ }
223+ }
0 commit comments