-
-
Save jwcastillo/d5c58ad09f2454e537c745c7fe7825c0 to your computer and use it in GitHub Desktop.
Pushing data from Oracle using utl_http and node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="/socket.io/socket.io.js"></script> | |
<script> | |
var socket = io.connect('http://www.example.com'); | |
socket.on('column_value', function (data) { | |
console.log(data); | |
$('#trigger').html(data.trigger) | |
$('#column-value').html(data.column_value) | |
}); | |
</script> | |
Column listener | |
<p id="trigger"></p> | |
<p id="column-value"></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('http').createServer(handler), | |
io = require('socket.io').listen(app), | |
fs = require('fs'); | |
app.listen(80); | |
var qs = require('querystring'); | |
var post_data | |
function handler(req, res) { | |
fs.readFile(__dirname + '/index.html', | |
function(err, data) { | |
if (req.method == 'POST') { | |
var body = ''; | |
req.on('data', function (data) { | |
body += data; | |
}); | |
req.on('end', function () { | |
post_data = qs.parse(body); | |
if (post_data.trigger == 'trigger_name') { | |
io.sockets.emit('column_value', post_data) | |
} | |
}); | |
} | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.end(data); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace trigger trigger_name | |
after update of column_name on table_name for each row | |
declare | |
req utl_http.req; | |
resp utl_http.resp; | |
v_param varchar2(500) := 'trigger=trigger_name&column_value=' || :new.column_name; | |
v_param_length number := length(v_param); | |
begin | |
req := utl_http.begin_request (url=>'http://www.example.com', method=>'POST'); | |
utl_http.set_header (r => req, name => 'Content-Type', value => 'application/x-www-form-urlencoded'); | |
utl_http.set_header (r => req, name => 'Content-Length', value => v_param_length); | |
utl_http.write_text (r => req, data => v_param); | |
resp := utl_http.get_response (r => req); | |
utl_http.end_response(resp); | |
end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update table_name set column_name = 'new value'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment