B4J Question Query work with mysql but not with mssql

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
I have modify DBUtils (thanks Erel) for work with Mysql (remove "[" and "]" in syntax) and it work fine
With MSsql and DBUtils without modify, in CreateTable (Table not exist) i have this error:
B4X:
CreateTable: CREATE TABLE IF NOT EXISTS [Prodotto] ([Id] INTEGER AUTO_INCREMENT PRIMARY KEY, [Codice] TEXT, [Prodotto] TEXT)
(SQLException) java.sql.SQLException: Sintassi non corretta in prossimità della parola chiave 'IF'.
(SQLException) java.sql.SQLException: Sintassi non corretta in prossimità della parola chiave 'TABLE'.
ott 21, 2016 5:34:44 PM com.mchange.v2.c3p0.SQLWarnings logAndClearWarnings
INFORMAZIONI: Preparing the statement failed: Sintassi non corretta in prossimità della parola chiave 'TABLE'.
java.sql.SQLWarning: Preparing the statement failed: Sintassi non corretta in prossimità della parola chiave 'TABLE'.
    at net.sourceforge.jtds.jdbc.TdsCore.microsoftPrepare(TdsCore.java:1248)
    at net.sourceforge.jtds.jdbc.JtdsConnection.prepareSQL(JtdsConnection.java:708)
    at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:1028)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:116)
    at anywheresoftware.b4j.objects.SQL.ExecQuery2(SQL.java:290)
    at b4j.DBGest.dbutils._executememorytable(dbutils.java:640)
    at b4j.DBGest.dbutils._executelist(dbutils.java:704)
.......

P.S.
With Sql work fine only with MSsql i have this problem. (Syntax wrong?)

Thanks
 

micro

Well-Known Member
Licensed User
Longtime User
Ok, with this query work

B4X:
Query = If  Not EXISTS (Select * FROM sys.tables WHERE name = N'Prodotto' AND type = 'U') BEGIN CREATE TABLE [dbo].[Prodotto] ([Id] INTEGER IDENTITY(1,1) PRIMARY KEY, [Codice] TEXT, [Prodotto] TEXT) END"

Only a question, why the table create has the Id column has not null as value to be assigned?
If i put NULL, it's not created
([Id] INTEGER NULL IDENTITY(1,1) PRIMARY KEY, [Codice] TEXT, [Prodotto] TEXT) END
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
From the ms sql reference page:

All columns defined within a PRIMARY KEY constraint must be defined as NOT NULL. If nullability is not specified, all columns participating in a PRIMARY KEY constraint have their nullability set to NOT NULL.
[/quote}
 
Upvote 0
Top