Este artigo foi revisão – acesse o link aqui
Sim…. replicação para firebird… não tem ? tem sim… só trabalhar um pouco – nem tudo é como visão de brigadeiro..
A replicação consistem manter DUAS ou mais tabelas com conteúdo iguais – de tal forma que se obtém o mesmo resultado em qualquer uma das duas bases de dados.
Existe dois lados na replicação – um que tem os dados que precisam ser levados para o outro (publisher-aquele que publica) – o outro que recebe os dados publicados pelo servidor (subscriptor-aquele que se candidata a receber os dados). Por último a combinação de ambos em um só – ele é tanto publisher como subscriptor da mesma tabela;
Fase do desenvolvimento
- Preparar o Publisher para publicar dados para replicação (banco de origem);
- Preparar o Subscriptor para receber os dados publicados (banco de destino);
- Codificar os componente que monitoram as alterações do Publisher;
- Codificar a transferências dos dados da origem para o destino;
A título ilustrativo, vou adotar a tabela de PEDIDOs como base
Considere a seguinte tabela:
[code lang=”SQL”]
create table PEDIDOS (dcto varchar(10),
data Date,
cliente integer,
total numeric(15,4));
[/code]
Preparando o banco de origem em firebird
Como base para a replicação, vou criar uma coluna nova na tabela de pedidos na origem para indicar a chave de referência para a replicação – para fugir dos tipos auto-incrementos (já escrevi como fazer isto aqui no blog) vou usar uma coluna para identificar a chave de replicação que receberá uma representação texto para um GUID
alter table PEDIDOS add GID varchar(38);
[OFF] antes que alguém questione… não dá para usar auto-incremento em razão de atender a pré-condição de que o dado dever ser o mesmo nos dois banco de dados (traduzindo – não podem ser diferentes)
A coluna GID vai receber um valor por “trigger” toda vez que for incluída na tabela
[code lang=”SQL”]
SET TERM ^ ;
ALTER TRIGGER REPL_PEDIDOS_GID ACTIVE
BEFORE INSERT OR UPDATE POSITION 0
AS
begin
/* Trigger Utilizado para Replicacao */
if ((new.gid is null)) then
new.gid = UUID_TO_CHAR( gen_uuid() );
end^
SET TERM ; ^
[/code]
[OFF] como se nota inclui na trigger o UPDATE – fiz isto para pegar linhas antigas que ainda não foram replicadas em nenhum processo anterior – caso ocorre uma replicação parcial;
Até aqui já temos a marcação de chave na tabela de origem para localizar as linhas que serão publicadas para replicação. Agora vamos criar uma tabela de controle de publicação das replicações
[code lang=”SQL”]
CREATE TABLE REPL_ITENS
(
TABELA Varchar(128), // recebe o nome da tabela alvo
GID Varchar(38), // recebe o GID da tabela alvo
TIPO Char(1), // I-insert U-update D-delete
DATA Date, // data e hora da alteração
ID integer, // sequencial interna
SESSION_ID integer // sessão da transação que criou – um luxo
);
CREATE INDEX REPL_ITENSDATA ON REPL_ITENS (DATA);
CREATE INDEX REPL_ITENSGID ON REPL_ITENS (GID);
CREATE INDEX REPL_ITENSID ON REPL_ITENS (ID);
CREATE INDEX REPL_ITENSTABELA ON REPL_ITENS (TABELA);
GRANT DELETE, INSERT, REFERENCES, SELECT, UPDATE
ON REPL_ITENS TO SYSDBA WITH GRANT OPTION;
[/code]
Vamos precisar de um GENERATOR para popular a coluna ID da tabela e uma trigger para popular com o valor do GENERATOR. ver também
[code lang=”SQL”]
CREATE GENERATOR REPL_ITENS_GEN_ID;
SET TERM ^ ;
CREATE TRIGGER REPL_ITENS_ID FOR REPL_ITENS ACTIVE
BEFORE INSERT POSITION 0
AS
begin /* Replicacao Storeware */
new.id = gen_id(REPL_ITENS_GEN_ID,1);
new.session_id = rdb$get_context(‘SYSTEM’,’SESSION_ID’);
new.data = cast(‘now’ as date);
end^
SET TERM ; ^
[/code]
[OFF] para este caso não usei o GUID – vamos precisar garantir uma sequência na tabela que seja em ordem crescente – isto vai facilitar a codificação a frente.
Para fechar, vamos ensinar a tabela PEDIDOS como publicar as suas alterações:
[code lang=”SQL”]
SET TERM ^ ;
CREATE TRIGGER REPL_PEDIDOS_REG FOR PEDIDOS ACTIVE
AFTER INSERT OR UPDATE OR DELETE POSITION 0
AS
begin
/* Replicacao Storeware */
in autonomous transaction do
begin
if (inserting) then
insert into repl_itens ( tabela,gid,tipo)
values(‘PEDIDOS’,new.gid,’I’);
if (updating) then
insert into repl_itens ( tabela,gid,tipo)
values(‘PEDIDOS’,new.gid,’U’);
if (deleting) then
insert into repl_itens ( tabela,gid,tipo)
values(‘PEDIDOS’,old.gid,’D’);
end
end
^
SET TERM ;
[/code]
You actually make it seem so easy with your presentation but I find this topic to be actually something that I think I would never understand. It seems too complex and very broad for me. I’m looking forward for your next post, I’ll try to get the hang of it!
occhiali ray ban fabrizio corona http://www.arredamenti73.it/menu/index.php?occhiali-ray-ban-fabrizio-corona-3001892
Yes! Finally someone writes about %keyword1%.
ray ban solbriller profil optik kolding http://www.fracchia1956.it/js/index.php?ray-ban-solbriller-profil-optik-kolding-37502849
Thank you for the auspicious writeup. It in reality was a amusement account it. Look complex to far brought agreeable from you! However, how could we communicate?
ray ban winkel den bosch 112 http://gelateriasilvano.it/font/index.php?ray-ban-winkel-den-bosch-112-49504558
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks a lot!
oakley airbrake salg http://www.mobili-iofrida.it/slidy/index.php?oakley-airbrake-salg-37000137
Hey there! Would you mind if I share your blog with my zynga group? There’s a lot of people that I think would really appreciate your content. Please let me know. Thanks
apertura asics madrid http://www.gribaudolegnami.it/img/index.php?apertura-asics-madrid-24500908
Neat blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog shine. Please let me know where you got your design. Kudos
oakley m忙nd 2016 danmark 0045 http://www.archimec.com/images/index.php?oakley-m忙nd-2016-danmark-0045-37004657
I read this piece of writing fully regarding the comparison of hottest and preceding technologies, it’s awesome article.
nike free run noir orange http://www.eurorettifica.it/temp/index.php?nike-free-run-noir-orange-36503970
Thanks in favor of sharing such a good opinion, article is fastidious, thats why i have read it fully
scarpe calcio nike mercurial vapor http://www.arcotecnica.it/fonts/index.php?scarpe-calcio-nike-mercurial-vapor-02000931
I tend not to leave a response, but after looking at some of the remarks here %BLOG_TITLE%. I actually do have some questions for you if it’s allright. Is it just me or do a few of these comments appear as if they are coming from brain dead visitors? 😛 And, if you are posting on additional sites, I would like to follow|keep up with} anything fresh you have to post. Could you post a list of the complete urls of your social networking pages like your twitter feed, Facebook page or linkedin profile?
oakley frogskin nicky hayden twitter http://www.ristorantedalia.it/img/index.php?oakley-frogskin-nicky-hayden-twitter-49002895
I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to design my own blog and would like to know where u got this from. thanks a lot
collezione occhiali da vista oakley http://www.nexttec.it/lib/index.php?collezione-occhiali-da-vista-oakley-02502438
Yes! Finally something about %keyword1%.
orange oakley radar path photochromic http://www.dadami.it/base/index.php?orange-oakley-radar-path-photochromic-37001413
Superb blog! Do you have any tips and hints for aspiring writers? I’m planning to start my own website soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally overwhelmed .. Any ideas? Thank you!
nike roshe run roze dames http://www.saisha.it/lib/index.php?nike-roshe-run-roze-dames-48500834
I think this is one of the most important info for me. And i’m glad reading your article. But want to remark on some general things, The web site style is wonderful, the articles is really excellent : D. Good job, cheers
ray ban aviator zonnebril goedkoop http://www.kitchensedesign.it/image/index.php?ray-ban-aviator-zonnebril-goedkoop-49500424
If you would like to take a great deal from this post then you have to apply such strategies to your won web site.
nike shoes leather brown http://www.ifuorimisura.it/lib/index.php?nike-shoes-leather-brown-60503106
whoah this weblog is great i like studying your posts. Stay up the great work! You understand, many people are hunting round for this information, you could help them greatly.
What’s up i am kavin, its my first time to commenting anyplace, when i read this post i thought i could also create comment due to this brilliant piece of writing.
Remarkable issues here. I’m very glad to see your article. Thank you so much and I am looking forward to contact you. Will you please drop me a mail?
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how can we communicate?
Does your blog have a contact page? I’m having a tough time locating it but, I’d like to send you an email. I’ve got some ideas for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.
Contact on facebook amarildolacerda
A motivating discussion is definitely worth comment. I do think that you ought to publish more about this issue, it might not be a taboo matter but usually folks don’t talk about such topics. To the next! Kind regards!!
Every weekend i used to visit this site, because i wish for enjoyment, since this this web page conations really pleasant funny information too.
Hello to every single one, it’s genuinely a good for me to visit this web site, it consists of helpful Information.
Tks
Greetings! Very useful advice in this particular post!
It’s the little changes that make the most significant changes.
Thanks for sharing!
Hello there, just became alert to your blog through Google, and found that
it is really informative. I’m going to watch out for brussels.
I will appreciate if you continue this in future.
Lots of people will be benefited from your writing.
Cheers!