SymmetricDS transform_column - symmetricds

I am facing a problem about symmtericds transform_column :
-- transform to mst_author From EAut
insert into sym_transform_table(
transform_id, source_node_group_id, target_node_group_id, transform_point, source_table_name,
target_table_name, delete_action, transform_order, column_policy, update_first,
last_update_by, last_update_time, create_time
) values (
'mst_author_2_EAut', 'pusat', 'cabang1', 'EXTRACT', 'EAut',
'mst_author', 'DEL_ROW', 1, 'SPECIFIED', 1,
'sym', current_timestamp, current_timestamp
);
insert into sym_transform_column
(transform_id, include_on, source_column_name, target_column_name, pk, transform_type,create_time, last_update_time)
values
('mst_author_2_EAut', '', 'AutId', 'author_id', 1, 'copy',current_timestamp, current_timestamp),
('mst_author_2_EAut', '', 'AutKey', 'author_name', 0, 'copy',current_timestamp, current_timestamp);
insert into sym_transform_column
(transform_id, include_on, source_column_name, target_column_name, pk, transform_type,create_time, last_update_time,transform_expression)
values
('mst_author_2_EAut', '*', 'AutRaw', 'input_date', 0, 'variable',current_timestamp, current_timestamp,'system_date');
The errors:
Failed sql was: insert into buku.mst_author () values ()
--------------> empty column and values
Failed sql parameters: []
Failed sql parameters types: []
Failed row data was: "112950","1","0","0"," ","Name","\last,
first","100" [cabang1-001] - DataLoaderService - Failed to load batch
000-92 org.jumpmind.db.sql.SqlException: Field 'author_name' doesn't
have a default val ue at
org.jumpmind.db.sql.AbstractSqlTemplate.translate(AbstractSqlTemplate
Any help is appreciated
notes:
AutId is SQL Server Identity and author_id is MySQL auto increment

There's a column 'author_name' at the target node that either doesn't exist at the source or its value is null. If there's a constraint 'not null' at the target declare a default value by 'alter table mst_author add constraint not null default value '' on column author_name' or something along these lines
I would recommend to add all source and target column transformations even if the column names are equal, not only the ones that are different

Related

t-sql insert statement where primary key is a decimal

2 years ago I created a table that has 22 rows. Each row is a step/page in filing an application for hire. I realized back then I would most likely be asked to insert steps as the business grew. I was right. I need to insert a new step between step 21 & 22. So I want to create a new row in that table with stepId = 21.5. But the insert statement fails.
INSERT INTO frznStep (
stepId
,myField1
,myField2
,myField3
)
VALUES (
21.5
,'xxx'
,'yyy'
,'zzz'
)
the error msg is:
Violation of PRIMARY KEY constraint 'PK_frznStep'. Cannot insert
duplicate key in object 'dbo.frznStep'. The duplicate key value is
(22).
I suspect when you script out the table, you'll see that the precision of your decimal column is 0, so something like stepId decimal(9,0)
If you have a non-zero value for the decimal precision, the following repro works
USE tempdb
DROP TABLE IF EXISTS #frznStep;
CREATE TABLE #frznStep
(
stepId decimal(9, 1) NOT NULL
, myField1 varchar(255) NOT NULL
, myField2 varchar(255) NOT NULL
, myField3 varchar(255) NOT NULL
, CONSTRAINT PK_frznStep PRIMARY KEY (stepId)
);
insert into #frznStep (stepId, myField1, myField2, myField3) values (21, 'www', 'yyy', 'zzz');
insert into #frznStep (stepId, myField1, myField2, myField3) values (22, 'yyy', 'yyy', 'zzz');
insert into #frznStep (stepId, myField1, myField2, myField3) values (21.5, 'xxx', 'yyy', 'zzz');
GO
When you use a 0 scale, you'll get 21 and 22 into the table but 21.5 will be implicitly converted to decimal(x,0) which then violates the primary key constraint.
-- Redeclare as 0 precision
DROP TABLE IF EXISTS #frznStep;
CREATE TABLE #frznStep
(
stepId decimal(9, 0) NOT NULL
, myField1 varchar(255) NOT NULL
, myField2 varchar(255) NOT NULL
, myField3 varchar(255) NOT NULL
, CONSTRAINT PK_frznStep PRIMARY KEY (stepId)
);
insert into #frznStep (stepId, myField1, myField2, myField3) values (21, 'www', 'yyy', 'zzz');
insert into #frznStep (stepId, myField1, myField2, myField3) values (22, 'yyy', 'yyy', 'zzz');
--Msg 2627, Level 14, State 1, Line 36
--Violation of PRIMARY KEY constraint 'PK_frznStep'. Cannot insert duplicate key in object 'dbo.#frznStep'. The duplicate key value is (22).
--The statement has been terminated.
insert into #frznStep (stepId, myField1, myField2, myField3) values (21.5, 'xxx', 'yyy', 'zzz');
You options are either to change your data type to include the scale (which will require dropping and recreating the primary key as the column is part of it) Or scale everything up by a factor of 10 and then you can insert into the 215 nicely between 210 and 220. (A "trick" I learned the hard way programming Apple Basic ages ago)
The first intuitive answer off the bat would be to convert your primary key to a numeric type, such as decimal.
However, is there really a reason to think of the step as 21.5? Or are you just trying to fit it between 21 and 22? I say this because the more ideal situation would be to have a primary key that simply serves as an identity. Then have a separate column that identifies the step number. That way, instead of having the step be 21.5, you'll simply have it be step 22, and then you can change step 22 to step 23.
alter table frznStep add column stepOrd int null;
update frznStep set stepOrd = stepId;
update frznStep set stepOrd = 23 where stepOrd = 22;
insert frznStep (stepId, stepOrd, ...) values (100, 22, ...);
You could also convert stepId to autoincrement. Though I believe you'll have to drop the table and recreate it in that case.
You’re getting the error because your id column is effectively integer and your attempted insert value is being rounded to integer, thus colliding with an existing key value.
Rather than using the id column as both unique identifier and step order, which is a design flaw (overloading a column), specify the steps as a chain, like a linked list, by introducing a column, perhaps called nextStepId, that stores the id of the next step to run.
This would separate the concerns of primary key being the row identifier and step order, giving control of step order independent of id values being any particular value relative to each other.

symmetricds sym_outgoing_batch.node_id=-1

There are two batch message in sym_outgoing_batch and one of the node_id is 000 (corp) another is -1 (what's this -1 means?) when I pull many data from store to corp. Part of data is successful to router timely but other is delayed. The message is as follows:
and the configuration file is as follows:
insert into sym_channel(channel_id, processing_order, max_batch_size, enabled, description)
values('sale_channel', 1, 1000000, 1, 'sale data from store to corp');
insert into sym_trigger(trigger_id, source_table_name, channel_id, last_update_time, create_time)
values('sale_pay_triger', 'D_T_BILL_PAY', 'sale_channel', current_timestamp, current_timestamp);
insert into sym_router(router_id, source_node_group_id, target_node_group_id, router_type,router_expression, create_time, last_update_time)
values('store_2_corp_sheftnotnull', 'store', 'corp', 'bsh', 'CSHIFT_C!=null && !CSHIFT_C.equals("")',current_timestamp, current_timestamp);
insert into sym_trigger_router(trigger_id, router_id, initial_load_order, last_update_time, create_time)
values('sale_pay_triger', 'store_2_corp_sheftnotnull', 1, current_timestamp, current_timestamp);
insert into SYM_CONFLICT(CONFLICT_ID,SOURCE_NODE_GROUP_ID,TARGET_NODE_GROUP_ID,DETECT_TYPE,RESOLVE_TYPE,PING_BACK,CREATE_TIME,LAST_UPDATE_TIME)
values('conflict_fallback', 'corp', 'store', 'USE_PK_DATA', 'FALLBACK', 'OFF', current_timestamp, current_timestamp);
commit;
If you are asking what does a node_id of -1 mean. It means that the data was un-routed. There were no nodes that met the routing condition.

Trigger That updates the status of a video if it gets rented out or returned

I am creating a Trigger That updates the status of a video if it gets rented out or returned. At the bottom is my trigger, but it has errors. The following errors are as follows.
LINE/COL ERROR
6/28 PLS-00103: Encountered the symbol "IF" when expecting one of the following: ( - + case mod new not null avg coun t current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date pipe < an alternatively-quoted string literal with c haracter set specification>
6/51 PLS-00103: Encountered the symbol ";" when expecting one of the f ollowing: * & - + / at mod remainder rem then and or || multiset
--Video TABLE
CREATE TABLE Video(
Vid_Num VARCHAR2(10),
Category VARCHAR2(30),
Status VARCHAR2(15),
Title VARCHAR2(30),
Catalog_Num VARCHAR2(10),
Rental_fee NUMBER(8,2),
Cost NUMBER(8,2),
Main_Actors VARCHAR2(100),
Director VARCHAR2 (50),
Rental_Code VARCHAR2(10) CONSTRAINT Rental_ID_FK REFERENCES Rental(Rental_Code),
Num_Copies NUMBER(4),
CONSTRAINT Vid_Num_PK PRIMARY KEY (Vid_Num, Catalog_Num));
--Insert for Video Table
INSERT INTO Video
VALUES ('V101','Action','Available','Expendables','C1','4.99','0','Stallone','Simon West','R101','2');
INSERT INTO Video
VALUES ('V102','Drama','Available','The Judge','C2','4.99','0','Robert Downey Jr','David Dobkin','R101','2');
INSERT INTO Video
VALUES ('V103','Family','Available','Lion King','C3','1.99','0','James Jones','Rogers Allers','R105','3');
INSERT INTO Video
VALUES ('V104','Suspense','Available','Saw II','C4','2.99','0','Tobin Bell','James Wan','R103','2');
INSERT INTO Video
VALUES ('V105','Sci-Fi','Available','Interstellar','C5','4.99','0','Matthew McConaughy','Christopher Nolon','R101','2');
INSERT INTO Video
VALUES ('V106','Action','Available','Hunger Games','C6','4.99','0','Jennifer Lawrence','Gary Ross','R101','2');
INSERT INTO Video
VALUES ('V107','Action','Available','I Am Legend','C7','1.99','0','Will Smith','Francis Lawerence','R105','2');
INSERT INTO Video
VALUES ('V108','Drama','Available','Hancock','C8','1.99','0','Will Smith','Peter Berg','R105','2');
INSERT INTO Video
VALUES ('V109','Comedy','Available','Billy Madison','C9','1.99','0','Adam Sandler','Tamara Davis','R105','2');
INSERT INTO Video
VALUES ('V110','Comedy','Available','Tommy Boy','C10','1.99','0','Chris Farley','Peter Segal','R105','2');
--Transaction Table
CREATE TABLE Transaction(
Rental_Num VARCHAR2(8) CONSTRAINT Rental_Num_PK PRIMARY KEY,
Mem_Num VARCHAR2(10) CONSTRAINT Member_Num_FK REFERENCES Member(Mem_Num),
Full_Name VARCHAR2(50),
Vid_Num VARCHAR2(10),
Title VARCHAR2(50),
Catalog_Num VARCHAR2(10),
Date_Rented_Out DATE,
Date_Returned DATE,
Rental_Code VARCHAR2(10) CONSTRAINT Rental_Code_FK REFERENCES Rental(Rental_Code),
Rental_fee NUMBER(8,2),
CONSTRAINT Video_Num_FK FOREIGN KEY(Vid_Num, Catalog_Num) REFERENCES Video(Vid_Num, Catalog_Num));
--Insert for Transaction Table
INSERT INTO Transaction
VALUES ('1','Mem102','OJ Simpson', 'V101', 'Expendables', 'C1', '14-Nov-14', '16-Nov-14', 'R101', '4.99');
INSERT INTO Transaction
VALUES ('2','Mem105','Donte Stallworth', 'V103', 'Lion King', 'C3', '14-Nov-14', '16-Nov-14', 'R105', '1.99');
INSERT INTO Transaction
VALUES ('3','Mem103','Ray Rice', 'V102', 'The Judge', 'C2', '14-Nov-14', '16-Nov-14', 'R101', '4.99');
INSERT INTO Transaction
VALUES ('4','Mem101','Mike Vick', 'V105', 'Intersteller', 'C5', '14-Nov-14', '16-Nov-14', 'R101', '4.99');
INSERT INTO Transaction
VALUES ('5','Mem104','Pacman Jones', 'V104', 'Saw II', 'C4', '14-Nov-14', '16-Nov-14', 'R103', '2.99');
INSERT INTO Transaction
VALUES ('6','Mem104','Pacman Jones', 'V106', 'Hunger Games', 'C6', '14-Nov-14', '16-Nov-14', 'R101', '4.99');
INSERT INTO Transaction
VALUES ('7','Mem104','Pacman Jones', 'V107', 'I Am Legend', 'C7', '14-Nov-14', '16-Nov-14', 'R105', '1.99');
INSERT INTO Transaction
VALUES ('8','Mem104','Pacman Jones', 'V108', 'Hancock', 'C8', '14-Nov-14', '16-Nov-14', 'R105', '1.99');
INSERT INTO Transaction
VALUES ('9','Mem104','Pacman Jones', 'V109', 'Billy Madison', 'C9', '14-Nov-14', '16-Nov-14', 'R105', '1.99');
INSERT INTO Transaction
VALUES ('10','Mem104','Pacman Jones', 'V110', 'Tommy Boy', 'C10', '14-Nov-14', '16-Nov-14', 'R105', '1.99');
--Trigger
CREATE or REPLACE Trigger Available_Rule
BEFORE INSERT ON Transaction
FOR EACH ROW
BEGIN
SELECT Date_Rented_Out,Date_Returned, Status
FROM Transaction, Video;
IF Date_Rented_Out > 0 AND IF Date_Returned = NULL;
THEN Status = Unavailable;
End IF;
ELSE
IF Date_Rented_Out > 0 AND IF Date_Rented > 0;
THEN Status = Available;
End IF;
END;
/
show errors;
The context of the current trigger's row values are available with the default, :new property. You
do not perform a select on the table you are triggered on. Instead try this (you may have to tweak a bit, but basic concept). Note that DATE data types are not checked against zero. It should either have a NULL value, or some other valid value. You will need to fix that. I would suggest spending some time reading about PL/SQL syntax also.
CREATE or REPLACE Trigger Available_Rule
BEFORE INSERT ON Transaction
FOR EACH ROW
BEGIN
IF :new.Date_Rented_Out is not null AND IF :new.Date_Returned = NULL
THEN
update video
set status = 'Available'
where vid_num = :new.vid_num;
End IF;
ELSE
-- etc. checks ---
END;
/

SQL Server - bulk insert column

I need to insert csv file into sql server db. The problem is I keep getting a
Bulk load data conversion error (type mismatch or invalid character for
the specified codepage) error. this is repeated 10 times and
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error.
The provider did not give any information about the error.
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
The specific column that errors is a bigint,primary key,no null field. I have made sure all 5000 records have a 4 digit number and there are no nulls. I am tired of fighting this and simply want to insert the date and datavalue fields into this table --CSResult. The problem is sql server simply errors out and I am thinking it wants values for ALL the fields.
IS there a way to insert data into the columns I want?
Any ideas.
BULK INSERT [DB].[CsSchema].[CsResult] (
FROM 'c:\june132012.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
this is what the data looks like:
3857,2011-05-19 04:00:00.000,Y,,82,N,N,,4,1,1,10,,1,,535/31706815
3858,2011-05-19 02:23:00.000,Y,,128,N,N,,4,1,1,10,,1,,535/31706815
Here is the DDL:
ResultID bigint notnull
ResultDate datetime,notnull
HasValue CHAR 1, notnull
Duration int, null
DataValue decimal 19,9, notnull
IsEdited CHAR 1, notnull
IsAnnotated CHAR 1, notnull
AddOnValue decimal 19,9, null
DataTypeID FK, int, notnull
ResultTypeID FK smallint, notnull
PatientID FK, int, notnull
DataSourceTypeID FK, smallint, notnull
MedicationID FK, int, null
DataDownloadID FK, int, null
SlotTypeID FK,smallint, null
DataSourceIdentity nvarchar 20, null

SQL - How to INSERT a foreign key as a value for a column

I know this is rather basic, and i've searched for answers for quite some time, but I'm troubled.
I don't know how to make my coding readable on here but here it is.
Here's the query for making the table in question:
CREATE TABLE customer
( customer_id INT NOT NULL CONSTRAINT customer_pk PRIMARY KEY IDENTITY,
first_name VARCHAR(20) NOT NULL,
surname VARCHAR(20) NOT NULL,
dob DATETIME NOT NULL,
home_address VARCHAR(50) NOT NULL,
contact_number VARCHAR(10) NOT NULL,
referrer_id INT NULL FOREIGN KEY REFERENCES customer(customer_id),
);
And here's the problem code:
--fill customer table
INSERT INTO customer
VALUES ( 'Harold', 'Kumar', '2010-07-07 14:03:54', '3 Blue Ln, Perth', 0812391245, NULL )
INSERT INTO customer
VALUES ( 'Bingo', 'Washisnameoh', '2010-09-21 12:30:07', '3 Red St, Perth', 0858239471, NULL )
INSERT INTO customer
VALUES ( 'John', 'Green', '2010-11-07 14:13:34', '4 Blue St, Perth', 0423904823, NULL )
INSERT INTO customer
VALUES ( 'Amir', 'Blumenfeld', '2010-11-01 11:03:04', '166 Yellow Rd, Perth', 0432058323, NULL)
INSERT INTO customer
VALUES ( 'Hank', 'Green', '2010-07-07 16:04:24', '444 Orange Crs, Perth', 0898412429, 8)
(Specifically the line with the 8 value at the end.)
When executing the second query it responds with this:
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted
with the FOREIGN KEY SAME TABLE constraint
"FK_customer_referr__5772F790". The conflict occurred in database
"master", table "dbo.customer", column 'customer_id'. The statement
has been terminated.
Appreciate your help with this.
1)
You have a primary key on customer_id - and your insert statements do not have value for customer id
2)
You have a self referencing foreign key in the form of referrer_id referring to customer_id.
When you are inserting a record with referrer_id which is not null, in your case which is '8', make sure you already inserted a record with customer_id '8'
How do you know that the referrer_id is supposed to be 8 ??
What you need to do is catch the value of the customer_id inserted, and then used that in your second query:
DECLARE #referToID INT
INSERT INTO dbo.Customer(first_name, surname, dob, home_address, contact_number, referrer_id)
VALUES ('Harold', 'Kumar', '2010-07-07 14:03:54', '3 Blue Ln, Perth', 0812391245, NULL)
SELECT #ReferToID = SCOPE_IDENTITY() ; -- catch the newly given IDENTITY ID
INSERT INTO dbo.Customer(first_name, surname, dob, home_address, contact_number, referrer_id)
VALUES ('Hank', 'Green', '2010-07-07 16:04:24', '444 Orange Crs, Perth', 0898412429, #ReferToID)
I don't know which row you want to refer to (you didn't specify) - but I hope you understand the mechanism:
insert the new row into your table
get the newly inserted ID by using SCOPE_IDENTITY
insert the next row which refers to that first row and use that value returned by SCOPE_IDENTITY
Update: if you really want to have a given row reference itself (strange concept.....), then you'd need to do it in two steps:
insert the new row into your table
get the newly inserted ID by using SCOPE_IDENTITY
update that row to set the referrer_id
Something like this:
DECLARE #NewCustomerID INT
INSERT INTO dbo.Customer(first_name, surname, dob, home_address, contact_number)
VALUES ('Hank', 'Green', '2010-07-07 16:04:24', '444 Orange Crs, Perth', 0898412429)
SELECT #NewCustomerID = SCOPE_IDENTITY() ; -- catch the newly given IDENTITY ID
UPDATE dbo.Customer
SET referrer_id = #NewCustomerID
WHERE customer_id = #NewCustomerID
The only problem you have here is the identity must have a seed value which can be like Identity(1,1) where the first 1 is the starting point and the send 1 is the auto seed number...the re run your insert statement

Resources