Menu

[2eb2a2]: / synchronization_table.php  Maximize  Restore  History

Download this file

278 lines (247 with data), 9.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php session_start(); ?>
<html>
<head>
<title>deltasql - Synchronization Table</title>
<link rel="stylesheet" type="text/css" href="deltasql.css">
<link rel="shortcut icon" href="pictures/favicon.ico" />
</head>
<?php
include("utils/constants.inc.php");
include("conf/config.inc.php");
include("utils/copypaste.inc.php");
include("head.inc.php");
if (!isset($default_copypaste)) $default_copypaste=1;
printCopyPasteJS($default_copypaste);
echo "<body>";
echo "<style type=\"text/css\">";
include ("deltasql.css");
echo "</style>";
$projectid=$_POST['frmprojectid'];
if ($projectid=="") die("<b><font color='red'>Please select a project!</font></b>");
$frmsourcebranchid = $_POST['frmsourcebranch'];
// retrevieng project name and branch name from ids
mysql_connect($dbserver, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
$query="SELECT name, dbtype,useclause FROM tbproject where id=$projectid";
$result=mysql_query($query);
$projectname=mysql_result($result,0,"name");
$frmdbtype=mysql_result($result,0,"dbtype");
$useclause=mysql_result($result,0,"useclause");
$query2="SELECT name FROM tbbranch where id=$frmsourcebranchid";
$result2=mysql_query($query2);
$frmsourcebranch=mysql_result($result2,0,"name");
mysql_close();
if ($frmdbtype=="") die("<b><font color='red'>Please edit this project and specify a database type!</font></b>");
if ($frmsourcebranch=="") $frmsourcebranch="HEAD";
echo "<h2>Synchronization Table</h2>";
echo "<p><i>Script to be created in the <b>$frmdbtype</b> database schema for the project <b>$projectname</b></i></p>";
printCopyPasteLink("Copy to clipboard", 0, $default_copypaste);
?>
<hr>
<pre>
<?php
$intro="";
$usestring = "";
if (($frmdbtype=="$db_other") || ($frmdbtype=="$db_sybase")) {
$intro = "-- you might need to adapt the following script to your database type\n" .
"-- the table TBSYNCHRONIZE is mandatory. the stored procedure DELTASQL_VERIFY_SCHEMA is optional.\n\n";
echo $intro;
}
if (($frmdbtype=="$db_oracle") || ($frmdbtype=="$db_other") || ($frmdbtype=="$db_sybase"))
$script = "
-- DROP TABLE TBSYNCHRONIZE;
CREATE TABLE TBSYNCHRONIZE
(
PROJECTNAME VARCHAR2(64) NOT NULL,
UPDATE_DT DATE DEFAULT SYSDATE NOT NULL,
UPDATE_USER VARCHAR2(64) NULL,
UPDATE_TYPE VARCHAR2(32) NULL,
VERSIONNR INTEGER NOT NULL,
BRANCHNAME VARCHAR2(128) NULL,
TAGNAME VARCHAR2(128) NULL,
UPDATE_FROMVERSION INTEGER NULL,
UPDATE_FROMSOURCE VARCHAR2(128) NULL,
DBTYPE VARCHAR2(32) NULL,
CONSTRAINT UN_VERSIONNR UNIQUE (VERSIONNR)
);
-- this stored procedure verifies that scripts are executed in the correct schema
CREATE OR REPLACE PROCEDURE DELTASQL_VERIFY_SCHEMA (versionExt INTEGER, branchnameExt VARCHAR2,projectnameExt VARCHAR2)
AS
versionV INTEGER;
branchnameV VARCHAR2(128);
projectnameV VARCHAR2(64);
BEGIN
SELECT versionnr INTO versionV FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
SELECT branchname INTO branchnameV FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
SELECT projectname INTO projectnameV FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
IF (branchnameV <> branchnameExt) OR (versionV <> versionExt) OR (projectnameV <> projectnameExt) then
raise_application_error(-20001, 'This script is for another schema or it was already executed!!!');
end IF;
END;
/
"; else
if ($frmdbtype=="$db_mysql")
$script = "
CREATE TABLE `tbsynchronize` (
`projectname` VARCHAR( 64 ) NOT NULL ,
`update_dt` DATE NULL ,
`update_user` VARCHAR( 64 ) NULL ,
`update_type` VARCHAR( 32 ) NULL ,
`versionnr` INT NOT NULL,
`branchname` VARCHAR( 128 ) NULL ,
`tagname` VARCHAR( 128 ) NULL ,
`update_fromversion` INT NULL,
`update_fromsource` VARCHAR( 128 ) NULL,
`dbtype` VARCHAR( 32 ) NULL ,
UNIQUE KEY `versionnr` (`versionnr`)
) ENGINE = MYISAM ;
";
/*
This mySQL code does not work
-- to execute in phpMyAdmin, define the delimiter in the SQL window as // in the editbox and remove the DELIMITER statements
DELIMITER //
DROP PROCEDURE IF EXISTS DELTASQL_VERIFY_SCHEMA //
CREATE PROCEDURE DELTASQL_VERIFY_SCHEMA(IN version INT, IN branchname CHAR(64), IN projectname CHAR(64))
up:BEGIN
DECLARE ver INT;
DECLARE bra CHAR(64);
DECLARE pro CHAR(64);
SET ver = (SELECT versionnr FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize));
SET bra = (SELECT branchname FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize));
SET pro = (SELECT branchname FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize));
IF (ver <> version) or (bra<>branchname) or (pro <> projectname) THEN
SELECT 'This script is for another schema!!!' AS `FALSE`;
LEAVE up;
END IF;
END;
//
DELIMITER ;
*/
else
if ($frmdbtype=="$db_sqlserver") {
if ($useclause!="") {
$usestring = "USE " . $useclause . ";\nGO\n";
}
$script = $usestring . "
-- DROP TABLE dbo.tbsynchronize;
CREATE TABLE dbo.tbsynchronize
(
projectname varchar(64) not null,
update_dt datetime default getdate() not null,
update_user varchar(64) null,
update_type varchar(32) null,
versionnr integer not null,
branchname varchar(128) null,
tagname varchar(128) null,
update_fromversion integer null,
update_fromsource varchar(128) null,
dbtype varchar(32) null,
CONSTRAINT un_versionnr UNIQUE (versionnr)
);
GO
" . $usestring . "
-- this function verifies that scripts are executed in the correct schema
CREATE PROCEDURE [dbo].[deltasql_verify_schema]
@versionExt int,
@branchnameExt varchar(128),
@projectnameExt varchar(64)
AS
BEGIN
DECLARE
@versionV int,
@branchnameV varchar(128),
@projectnameV varchar(64);
SELECT @versionV = max(versionnr) FROM tbsynchronize;
SELECT @branchnameV = branchname FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
SELECT @projectnameV = projectname FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
IF ((@branchnameV <> @branchnameExt) OR (@versionV <> @versionExt) OR (@projectnameV <> @projectnameExt))
BEGIN
RAISERROR('This script is for another schema or it was already executed!!!', 10, 1);
RETURN
END
PRINT 'This script can be executed here :-)'
END
GO
";
}
else
if ($frmdbtype=="$db_pgsql")
$script = "
-- DROP TABLE tbsynchronize;
CREATE TABLE tbsynchronize
(
projectname text,
update_dt timestamptz,
update_user text,
update_type text,
versionnr bigint UNIQUE,
branchname text,
tagname text,
update_fromversion bigint,
update_fromsource text,
dbtype character text
);
-- this function verifies that scripts are executed in the correct schema
CREATE OR REPLACE FUNCTION DELTASQL_VERIFY_SCHEMA (versionExt bigint, branchnameExt text, projectnameExt text)
RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
versionV bigint;
branchnameV text;
projectnameV text);
BEGIN
SELECT versionnr INTO versionV FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
SELECT branchname INTO branchnameV FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
SELECT projectname INTO projectnameV FROM tbsynchronize WHERE versionnr = (SELECT max(versionnr) FROM tbsynchronize);
IF (branchnameV <> branchnameExt) OR (versionV <> versionExt) OR (projectnameV <> projectnameExt) then
raise exception 'This script is for another schema or it was already executed!!!';
end IF;
END;
$$;
";
else
if ($frmdbtype=="$db_sqlite")
$script = "
CREATE TABLE tbsynchronize
(
projectname text,
update_dt text,
update_user text,
update_type text,
versionnr int primary key,
branchname text,
tagname text,
update_fromversion int,
update_fromsource text,
dbtype text
);
";
echo $script;
include("conf/config.inc.php");
include("utils/utils.inc.php");
mysql_connect($dbserver, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
$versionnr=get_global_version();
mysql_close();
$insert = $usestring .
"INSERT INTO tbsynchronize (PROJECTNAME, VERSIONNR, BRANCHNAME, UPDATE_USER, UPDATE_TYPE, DBTYPE)\n" .
"VALUES ('$projectname', $versionnr, '$frmsourcebranch', 'INTERNAL', 'deltasql-server', '$frmdbtype');\n";
echo "$insert";
$commit = "";
if ($frmdbtype=="$db_oracle") {
$commit = "COMMIT;\n";
} else
if ($frmdbtype=="$db_sqlserver") {
$commit = "GO\n";
}
echo $commit;
?>
</pre>
<?php
include("bottom.inc.php");
// repeating the script for copy&paste purposes
printCopyPasteBlock("$intro\n$script\n$insert\n$commit", $default_copypaste);
?>
</body>
</html>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.