symmetricds sym_outgoing_batch.node_id=-1 - symmetricds

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.

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.

I have two tables I want to retrieve the different results from same column in SQL

I have listed the actual table. From that I want the result as expected one.
Your issue is not that you have written in your problem. You first go to learn how to normalize the SQL or Tabular data. When you apply the second normal form this issue is resolved.
The given link provides a better understanding of normalization.
Normalization in SQL Tables
try this
CREATE TABLE demo (
jobPreference varchar(255),
Triggered varchar(255),
Success varchar(255),
opened varchar(255));
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('email-pwd reset', 'yes', 'success','yes');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('email-pwd reset', 'yes', 'success','yes');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('email-pwd reset', 'yes', 'fail','no');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('email-statement', 'yes', 'success','no');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('email-EMI reminder', 'yes', 'fail','no');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('SMS-loan EMI', 'yes', 'fail','no');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('SMS-confirmation', 'yes', 'fail','no');
INSERT INTO demo(jobPreference,Triggered,Success,opened) VALUES ('SMS-confirmation', 'yes', 'success','yes');
select SUBSTRING(jobPreference,0,CHARINDEX('-',jobPreference,0)) as Splitted
,jobPreference
,count(case Triggered when 'yes' then 1 else null end) as TriggeredCount
,count(case Success when 'success' then 1 else null end) as SuccessCount
,count(case opened when 'yes' then 1 else null end) as openedCount
from demo
group by jobPreference
For demo : https://rextester.com/ANPN26483

SymmetricDS transform_column

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

SQL Server DB Project Publish Empty string inserting a Zero

We are seeing a very strange problem when populating a field in a DB via a SQL Server DB project publish action.
This is the table definition
CREATE TABLE [dbo].[CatalogueItemExtensionFields]
(
[RowID] tinyint identity not null,
[FieldType] tinyint not null,
[Description] varchar(120) not null,
[Nullable] bit not null,
[DefaultValue] varchar(100) null,
[Active_Flag] bit null,
[OrderPriority] tinyint not null,
[ContextGuid] uniqueidentifier not null
);
This is the population script
set identity_insert CatalogueItemExtensionFields on
INSERT INTO CatalogueItemExtensionFields (rowid, fieldtype, description, nullable, defaultvalue, active_flag, orderpriority)
VALUES (dbo.ConstantProductGroupRowId(), 3, 'Product Group', 0, '', 1, dbo.ConstantProductGroupRowId()),
set identity_insert CatalogueItemExtensionFields off
If I run the INSERT script manually all works fine. When I run it as part of the DB project publish, it inserts "0".
I have looked at the publish.sql script that is generated, and all looks fine.
BTW, the only similar post I have found is this, but it does not apply to our case because the field we are inserting into is defined as varchar.
This is driving us mad. Any ideas?
We at our company finally found out that if you use SQLCMD / DBProj then it is super import to ENABLE Quoted Identifiers. Or else installer changes inputs in the exactly same way as #maurocam explained. If you enable this, then it works same as in SQL Management Studio for example.
To enable it:
SQLCMD
just use parameter -I (capital is important here, small is for file).
Example sqlcmd -S localhost -d DBNAME -U User -P Password -i path/to/sql/file.sql -I
SQL Itself
SET QUOTED_IDENTIFIER { ON | OFF }
DBProj
can be set at the project or object (proc, func, ...) level. Just click on a proj/file -> Properties and check if QUOTED_IDENTIFIER is enabled there.
For schema compare it can be set via "Ignore quoted identifiers"
https://learn.microsoft.com/en-us/sql/t-sql/statements/set-quoted-identifier-transact-sql?view=sql-server-ver16
APOLOGIES - MY MISTAKE!!! (But a very useful one to document)
I have summarised again below (also to make it clearer respect to my initial post)
TABLE DEFINITION
CREATE TABLE [dbo].[CatalogueItemExtensionFields]
(
[RowID] tinyint identity not null,
[FieldType] tinyint not null,
[Description] varchar(120) not null,
[Nullable] bit not null,
[DefaultValue] varchar(100) null,
[Active_Flag] bit null,
[OrderPriority] tinyint not null
);
INSERT STATEMENT
set identity_insert CatalogueItemExtensionFields on
INSERT INTO CatalogueItemExtensionFields (rowid, fieldtype, description, nullable, defaultvalue, active_flag, orderpriority) VALUES
(6, 3, N'Product Group', 0, N'', 1, 6),
(7, 2, N'Minimum Order Quantity', 1, NULL, 1, 7),
(8, 3, N'Additional HIBCs', 0, 1, 1, 8),
(9, 3, N'Additional GTINs', 0, N'', 1, 9)
set identity_insert CatalogueItemExtensionFields off
Because I am inserting multiple rows, when SQL parses the statement it see I am trying to insert a numeric defaultvalue = 1 for RowID = 8. As a result, even though the column is defined as a varchar, SQL decides that the INSERT statement is inserting INTs. So the empty string values (for RowIDs 7 and 9) are converted to zero. I referred to a post I had found relating to actual INT column, which results in the same behaviour.
If I instead run the following statement, with a default value of '1' for RowID = 8, it all works fine.
INSERT INTO CatalogueItemExtensionFields (rowid, fieldtype, description, nullable, defaultvalue, active_flag, orderpriority) VALUES
(6, 3, N'Product Group', 0, N'', 1, 6),
(7, 2, N'Minimum Order Quantity', 1, NULL, 1, 7),
(8, 3, N'Additional HIBCs', 0, '1', 1, 8),
(9, 3, N'Additional GTINs', 0, N'', 1, 9)
So, now the question is, why does SQL server ignore the column type definition and instead decides the type from the value in my INSERT statement?
Answer from SqlServerCentral
"empty string converts to an int without an error, and it's value is zero. it has to do with the precidence of implicit conversions"

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;
/

Resources