is it possible to use postgresql mode in flow test?
i have try to overwrite datasource.
val nodeConfig = MockNodeConfigOverrides(
extraDataSourceProperties =
mapOf("dataSource.url"
to "jdbc:h2:mem:partya_persistence;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE")
)
nodeA = mockNet.createNode(legalName = CordaX500Name("PartyA", "London", "GB"),configOverrides = nodeConfig)
but error with startup
Unknown data type: "blob"; SQL statement:
CREATE TABLE public.node_info_party_cert (party_name NVARCHAR(255) NOT NULL, ismain BOOLEAN NOT NULL, owning_key_hash NVARCHAR(130), party_cert_binary BLOB) [50004-199] [Failed SQL: CREATE TABLE public.node_info_party_cert (party_name NVARCHAR(255) NOT NULL, ismain BOOLEAN NOT NULL, owning_key_hash NVARCHAR(130), party_cert_binary BLOB)] {changeSet=migration/node-info.changelog-init.xml::1511451595465-11::R3.Corda, databaseChangeLog=master.changelog.json}
PostgreSQL mode is not supported in the mock node, but you can use Postgres when using driver test. You can check out documentation about is here.
Related
My setup detail is as follows
Corda 4.6 enterprise version
Database : Oracle 12
I am doing production database setup by refering https://docs.corda.net/docs/corda-enterprise/4.6/node/operating/node-database-admin.html. I created 2 database schemas (Admin and restricted access) for each node. I updated node.conf database connection as per given in docuemntation. I also given permission to my_user to access my_admin_user
dataSourceProperties = {
dataSourceClassName = "oracle.jdbc.pool.OracleDataSource"
dataSource.url = "jdbc:oracle:thin:#<host>:<port>:<sid>"
dataSource.user = my_user
dataSource.password = "my_password"
}
database = {
schema = my_admin_user
}
However getting below error while I start nodes
2021-06-09T16:36:16,400 ERROR databaseInitialisation DatabaseInitialisation(id="rK2VjTKa";status="error";error_code="1";message="**ORA-01031: insufficient privileges** [Failed SQL: CREATE TABLE my_user.DATABASECHANGELOG (ID VARCHAR2(255) NOT NULL, AUTHOR VARCHAR2(255) NOT NULL, FILENAME VARCHAR2(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED INTEGER NOT NULL, EXECTYPE VARCHAR2(10) NOT NULL, MD5SUM VARCHAR2(35), DESCRIPTION VARCHAR2(255), COMMENTS VARCHAR2(255), TAG VARCHAR2(255), LIQUIBASE VARCHAR2(20), CONTEXTS VARCHAR2(255), LABELS VARCHAR2(255), DEPLOYMENT_ID VARCHAR2(10))]")
2021-06-09T16:36:16,413 ERROR net.corda.node.internal.NodeStartupLogging **ORA-01031: insufficient privileges**
[Failed SQL: CREATE TABLE my_user.DATABASECHANGELOG (ID VARCHAR2(255) NOT NULL, AUTHOR VARCHAR2(255) NOT NULL, FILENAME VARCHAR2(255) NOT NULL, DATEEXECUTED TIMESTAMP NOT NULL, ORDEREXECUTED INTEGER NOT NULL, EXECTYPE VARCHAR2(10) NOT NULL, MD5SUM VARCHAR2(35), DESCRIPTION VARCHAR2(255), COMMENTS VARCHAR2(255), TAG VARCHAR2(255), LIQUIBASE VARCHAR2(20), CONTEXTS VARCHAR2(255), LABELS VARCHAR2(255), DEPLOYMENT_ID VARCHAR2(10))]
The problem has been resolved after adding following entry under dataSourceProperties in node.conf
connectionInitSql="alter session set current_schema=my_admin_user"
I'm working on unix/rhel7 system. I have installed require drivers for FreeTDS, unixODBC and pyodbc.Other query is working fine but when I'm trying execute stored proc with TVP (table valued parameter), its giving me error. Is there any way to connect SQL Server using windows service account from python?
Example:
import pyodbc;
cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER=SERVERNAME;PORT=1234;UID=USERNAME;PWD=PASSWORD;DATABASE=DBNAME')
cnxn.cursor()
param_array = []
for i in range(3):
param_array.append(['abc', 'adi', '/somepath/', '2021-01-04', 'NEW'])
result_array = cursor.execute("EXEC abc.stored_proc_name ?", [param_array]).fetchall()
cursor.commit()
cnxn.close()
Error:
pyodbc.Error: ('HY004', '[HY004] [FreeTDS][SQL Server]Invalid data type (0) (SQLBindParameter)')
So Is there any other way to connect SQL service account from python which supports TVP? Or Is there any solution in above example?
FreeTDS ODBC does not directly support table-valued parameters (TVPs) as discussed here. However we can use a temporary table and an anonymous code block to work around the issue. For a user-defined table type
USE [myDb]
GO
/****** Object: UserDefinedTableType [dbo].[dboListInt] Script Date: 2021-02-18 10:53:17 ******/
CREATE TYPE [dbo].[dboListInt] AS TABLE(
[Id] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
GO
and a stored procedure that accepts that table type
USE [myDb]
GO
/****** Object: StoredProcedure [dbo].[dboPyOdbcTestTvp] Script Date: 2021-02-18 10:41:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[dboPyOdbcTestTvp](#tvp [dbo].dboListInt READONLY)
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM #tvp
END
we can call the stored procedure and retrieve the results like so:
import pyodbc
cnxn = pyodbc.connect(
"DRIVER=FreeTDS_1.2.18;"
"SERVER=192.168.0.179;"
"PORT=49242;"
"DATABASE=myDb;"
"UID=sa;PWD=_whatever_;"
)
crsr = cnxn.cursor()
crsr.execute("CREATE TABLE #tvp_data (Id int)")
tvp_data = [(123, ), (234, ), (345, )]
crsr.executemany(
"INSERT INTO #tvp_data (Id) VALUES (?)",
tvp_data
)
crsr.execute("""\
SET NOCOUNT ON;
DECLARE #tvp dbo.dboListInt;
INSERT INTO #tvp (Id)
SELECT Id FROM #tvp_data;
EXEC dbo.dboPyOdbcTestTvp #tvp;
""")
print(crsr.fetchall())
# [(123, ), (234, ), (345, )]
I want to use HSQL for integration tests. Therefore I want to setup the test schema with exact the same script I use for production. This is in postgresql dialect. In the test script I tried to set the dialect but it doesn't seem to work.
At least for uuid datatype and constraints I get syntax error exceptions. E.g. I get a:
CREATE TABLE testtable ( id bigint NOT NULL, some_uuid uuid NOT NULL,
name character varying(32) NOT NULL, CONSTRAINT testtable PRIMARY KEY
(id) ) WITH ( OIDS=FALSE ); nested exception is
java.sql.SQLSyntaxErrorException: type not found or user lacks
privilege: UUID
for the following script:
SET DATABASE SQL SYNTAX PGS TRUE;
CREATE TABLE testtable
(
id bigint NOT NULL,
some_uuid uuid NOT NULL,
name character varying(32) NOT NULL,
CONSTRAINT testtable PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
And I get:
Failed to execute SQL script statement #2 of class path resource
[setupTestData.sql]: CREATE TABLE testtable ( id bigint NOT NULL, name
character varying(32) NOT NULL, CONSTRAINT testtable PRIMARY KEY (id)
) WITH ( OIDS=FALSE ); nested exception is
java.sql.SQLSyntaxErrorException: unexpected token: (
for this script:
SET DATABASE SQL SYNTAX PGS TRUE;
CREATE TABLE testtable
(
id bigint NOT NULL,
--some_uuid uuid NOT NULL,
name character varying(32) NOT NULL,
CONSTRAINT testtable PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
HSQLDB 2.3.4 and later supports UUID.
HSQLDB does not currently support the PostgreSQL extension WITH (ODS= FALSE)
I'm trying to create some deployment tools and I don't want to use BTEQ. I've been trying to work with the Teradata.Client.Provider in PowerShell but I'm getting syntax errors on the creation of a table.
[Teradata Database] [3706] Syntax error: expected something between
';' and the 'IF' keyword.
SELECT * FROM DBC.TablesV WHERE DatabaseName = DATABASE AND TableName = 'MyTable';
IF ACTIVITYCOUNT > 0 THEN GOTO EndStep1;
CREATE MULTISET TABLE MyTable ,
NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
MyColId INTEGER GENERATED ALWAYS AS IDENTITY
(START WITH 1
INCREMENT BY 1
MINVALUE 0
MAXVALUE 2147483647
NO CYCLE)
NOT NULL,
MyColType VARCHAR(50) NULL,
MyColTarget VARCHAR(128) NULL,
MyColScriptName VARCHAR(256) NULL,
MyColOutput VARCHAR(64000) NULL,
isMyColException BYTEINT(1) NULL,
ExceptionOutput VARCHAR(64000) NULL,
MyColBuild VARCHAR(128) NULL,
MyColDate TIMESTAMP NOT NULL
)
PRIMARY INDEX PI_MyTable_MyColLogId(MyColLogId);
LABEL EndStep1;
I would rather not use BTEQ as I've not found it has worked well in other deployment tools we have created and requires a bit of hacks. Is there anything I can use that would avoid using that tool?
What Parse error?
The CREATE will fail due to double INTEGER in MyColId and VARCHAR(max) in ExceptionOutput, it's an unknown datatype in Teradata.
In a table as below:
CREATE TABLE "active_mtrs"
(
"mtr_ID" INTEGER PRIMARY KEY NOT NULL,
"status" INTEGER,
"NIrSTime" DATETIME,
"NIrETime" DATETIME
)
I defined a trigger as:
CREATE TRIGGER "main"."replace1"
AFTER INSERT ON "active_mtrs" FOR EACH ROW
BEGIN
DECLARE #NIrSTime DATETIME;
DECLARE #NIrETime DATETIME;
DECLARE #mtr_ID INTEGER DEFAULT 0;
SELECT #mtr_ID = mtr_ID FROM INSERTED;
SELECT #NIrSTime = NIrSTime,#NIrETime = NIrETime
FROM subscriber
WHERE mtr_ID = #mtr_ID;
UPDATE active_mtrs
SET NIrSTime = #NIrSTime,
NIrETime = #NIrETime
WHERE mtr_ID = #mtr_ID;
END
where subscriber is another table in this database.
But I get an error:
[ near "DECLARE": syntax error ]
Exception Name: NS_ERROR_FAILURE
Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
What is my problem?
Your problem is that you are trying to use a different SQL dialect in SQLite.
You cannot use DECLARE; you have to look up the values directly:
CREATE TRIGGER main.replace1
AFTER INSERT ON active_mtrs
FOR EACH ROW
BEGIN
UPDATE active_mtrs
SET (NIrSTime, NIrETime) =
(SELECT NIrSTime, NIrETime
FROM subscriber
WHERE mtr_ID = NEW.mtr_ID)
WHERE mtr_ID = NEW.mtr_ID;
END;