IMPLEMENTATION AND TESTING
5.1
Implementation
User will input the number of data in textfield and submit it into program.
index.php
1. <form action="saveToDatabase.php" method="post">
2. Jumlah Data<input type="text" size="2" name="data"> 3. <br>
4. <button type="submit" name="submit">Make Table</button> 5. </form>
Codes above, in row 2 is a textfield which used for inputing
n
data. While
in row 1 and 4 , the
n
is submitted to saveToDatabase.php .
saveToDatabase.php
6. $row = $_POST["data"]; 7. $col = $_POST["data"];
8. $prosesQuery = 'call spFirstTimeRunning();
Codes above, in row 1 there is variable “row”, while in row 2 there is
variable “col”. They are contain
n
data. In row 3, it calls stored function
“spFirstTimeRunning()” which in it consist of process to create tables.
saveToDatabase.php
1. for($i=0;$i<$row;$i++) 2. {
3. $sql='insert into tblPekerjaan values("'.$x.'","x'.$x.'")'; 4. $result = $conn->query($sql);
5. $x=$x+1; 6. }
The main meaning of the codes above is code which generates jobs
automatically. Where in row 1, the codes in row 3 to 5 will be looped as much as
n.
While in row 3, it is MySQL syntax to insert values into tblPekerjaan. The
14
values are job's index and job's name. Job's index is number 1, 2, 3, ...,
n. W
hile
job's name is named
x1, x2,..., xn
. In row 4, its function is to run the syntax in row
3 into MySQL. In row 5, its function is to add
x
value where
x
is used for job's
index and job's name variable.
saveToDatabase.php
1. for($i=0;$i<$row;$i++) 2. {
3. $sql='insert into tblPelaku values("'.$x.'", "'.chr(64$x).'")';
4. $result = $conn->query($sql);
5. $x=$x+1;
6. }
The main meaning of the codes above is code which generates workers
automatically. Where in row 1, the codes in row 3 to 5 will be looped as much as
n.
While in row 3, it is MySQL syntax to insert values into tblPelaku and there is
char function which is used to convert number into char. The values are worker's
index and worker's name. Worker's index is number 1, 2, 3, ...,
n. W
hile
worker's
name is named
A,B,C, …,n
. In row 4, its function is to run the syntax in row 3 into
MySQL. In row 5, its function is to add
x
value where
x
is used for worker's index
and worker's name variable.
dbSkripsi.sql
1. create procedure spGenerateAngka(jmlData int) 2. begin
3. declare i,j int default 1; 4. declare randomx int;
5. declare status varchar(100); 6. declare batasMax int;
7. declare batasMin int; 8. set batasMax = 100; 9. set batasMin = 40; 10. set status = 'false'; 11. set i=1;
12. while i <= jmlData do 13. set j=1;
14. while j <= jmlData do
15. set status = 'false';
16. while status !='true' do
17. SELECT ROUND(RAND()*batasMax) into randomx;
18. if(randomx<batasMax and randomx>batasMin) then
19. insert into tblRelasi values(j,i,randomx);
20. set status = 'true';
22. end while;
23. set j=j+1;
24. end while; 25. set i = i+1; 26. end while; 27. end;
The main meaning of codes above is code which generates random
numbers as much as (
n
x
n
) as costs data. In row 1, it is code to create procedure
with name is spGenerateAngka which has integer parameter, it is
jmlData.
Where
parameter
jmlData
contains
n.
In row 3 to 10, the codes function to declare and
set value in variables. In row 15 to 21, consist of code which will random
numbers and insert them into tblRelasi. The numbers have maximum and
minimum value, they are in variable
batasMax
and
batasMin.
The random code
will always loop as long as
while
status is
not
true
or
false.
If the result of random
number is in range
batasMax
and
batasMin,
it will be inserted into tblRelasi and
the status will change to be
true
. In row 14, the code will loop codes in row 15 to
23
.
In row 12, the code will loop codes in row 13 to 25.
dbSkripsi.sql
1. delimiter $$
2. create procedure spInputIntoTable() 3. begin
4. declare i,j,k int default 1; 5. declare tmp int;
6. declare idNama int; 7. declare idKerjaan int; 8. declare idNamaRelasi int; 9. declare idKerjaanRelasi int; 10. declare tarifRelasi int; 11. declare nama varchar(100); 12. declare kerjaan varchar(100); 13. declare angka int;
14. declare jmlData int; 15. declare totalData int; 16. declare P varchar(100);
17. declare dinamis varchar(100); 18. declare kursorPelaku cursor for
19. select * from tblPelaku;
20. declare kursorKerjaan cursor for 21. select * from tblPekerjaan; 22. declare kursorRelasi cursor for
24. select count(*) from tblPekerjaan into jmlData; 25. set totalData = jmlData*jmlData;
26. select '' as '==========Data Asal=========='; 27. open kursorPelaku;
28. while i <= jmlData do
29. fetch kursorPelaku into idNama, nama; 30. insert into tblProses values (nama);
31. set i = i+1;
32. end while;
33. close kursorPelaku; 34. open kursorKerjaan; 35. while j <= jmlData do
36. fetch kursorKerjaan into idKerjaan, kerjaan;
37. set @query = concat('alter table tblProses add column ',kerjaan,' int');
38. PREPARE QUERY FROM @query;
39. EXECUTE QUERY;
40. DEALLOCATE PREPARE QUERY;
41. set j = j+1;
42. end while;
43. close kursorKerjaan; 44. set i = 1;
45. set j = 1;
46. open kursorKerjaan; 47. while i <= jmlData do
48. set j=1;
49. fetch kursorKerjaan into idKerjaan, kerjaan;
50. open kursorPelaku;
51. while j <= jmlData do
52. fetch kursorPelaku into idNama, nama;
53. select tblRelasi.tarif
54. from tblRelasi, tblPelaku, tblPekerjaan
55. where tblRelasi.idPelaku =
tblPelaku.idPelaku and tblRelasi.idPekerjaan = tblPekerjaan.idPekerjaan and tblPelaku.namaPelaku=nama and tblPekerjaan.namaPekerjaan = kerjaan into angka;
56. set @query= concat('update tblProses
set ',kerjaan,' = ',angka,' where kolom1=', '"',nama,'"');
57. PREPARE QUERY FROM @query;
58. EXECUTE QUERY;
59. DEALLOCATE PREPARE QUERY;
60. set j=j+1;
61. end while;
62. close kursorPelaku;
63. set i=i+1;
64. end while;
66. end; 67. $$
68. delimiter ;
The main meaning of codes above is about the program inputs workers,
jobs, and costs data into table. In row 2, it is code to create stored procedure
named spInputIntoTable(). In row 4 to 17, it is code to declare variables. In row
18 to 23 , it is code to declare cursors and set their data. In row 27 to 33, it is code
to fetch data in cursor kursorPelaku into table tblProses to be the rows name. In
row 34 to 43, it is code to fetch data in cursor kursorKerjaan into table tblProses
to be the columns name. In row 46 to 65, it is code to map costs data into table
tblProses.
dbSkripsi.sql
1. create procedure spFindMinimBaris() 2. begin
3. declare i,j,k int default 1;
4. declare minim int default 999999999; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
10. declare namaKolom varchar(100); 11. declare namaPelaku varchar(100); 12. declare namaKolomPelaku varchar(100); 13. declare angka int;
14. declare jmlPelaku int; 15. declare x int;
16. declare kursorNamaKolom cursor for
17. select column_name
18. from information_schema.columns 19. where table_name='tblProses'; 20. declare kursorNamaBaris cursor for 21. select kolom1 from tblProses; 22. declare kursorNilaiMinim cursor for 23. select * from tblMinimBaris;
24. select count(kolom1) from tblProses into jmlPelaku; 25. select count(*)
26. from information_schema.columns
27. where table_name = 'tblProses' into jmlKolom; 28. select '' as '==========Minim Baris=========='; 29. open kursorNamaBaris;
30. while i <= jmlPelaku do
31. fetch kursorNamaBaris into namaPelaku;
33. set minim = 999999999;
34. open kursorNamaKolom;
35. while j <= jmlKolom do
36. fetch kursorNamaKolom into
namaKolom;
37. if (j > 1) then
38. set @query := concat('select
',namaKolom,' from
tblProses where kolom1 = "',namaPelaku,'" into @angka');
39. prepare query from @query;
40. execute query;
41. deallocate prepare query;
42. select @angka into angka;
43. set temp = angka;
44. if(minim = 999999999) then
45. set minim = temp;
46. elseif(angka <= minim ) then
47. set minim = angka;
48. end if;
49. end if;
50. set j = j+1;
51. end while;
52. set totalMinim = totalMinim + minim;
53. insert into tblMinimBaris values(minim);
54. close kursorNamaKolom;
55. set i = i+1;
56. end while;
57. close kursorNamaBaris;
58. insert into tblTotalNilaiMinim values(totalMinim); 59. select * from tblMinimBaris;
60. end;
The main meaning of the codes above is to find minimum cost each row.
In row 1, it is code to create stored procedure spFindMinimBaris(). Codes in row
29 to 57, it is about finding the minimum cost each row by looping costs in rows
to columns. Each minimum cost in row is added to the other to get the total minim
cost. In row 58, it is code to insert the total minim cost into table
tblTotalNilaiMinim.
dbSkripsi.sql
1. create procedure spNorRow() 2. begin
5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
10. declare namaKolom varchar(100); 11. declare namaPelaku varchar(100); 12. declare namaKolomPelaku varchar(100); 13. declare angka int;
14. declare jmlPelaku int; 15. declare x int;
16. declare kursorNamaKolom cursor for
17. select column_name
18. from information_schema.columns 19. where table_name='tblProses'; 20. declare kursorNamaBaris cursor for 21. select kolom1 from tblProses; 22. declare kursorNilaiMinim cursor for 23. select * from tblMinimBaris;
24. select count(kolom1) from tblProses into jmlPelaku; 25. select count(*)
26. from information_schema.columns
27. where table_name = 'tblProses' into jmlKolom;
28. select '' as '==========Normalisasi Baris=========='; 29. open kursorNamaBaris;
30. open kursorNilaiMinim; 31. while i <= jmlPelaku do
32. fetch kursorNamaBaris into namaPelaku;
33. fetch kursorNilaiMinim into minim;
34. set k = 1;
35. open kursorNamaKolom;
36. while k <= jmlKolom do
37. fetch kursorNamaKolom into
namaKolom;
38. if (k > 1) then
39. set @query = concat('select ',
namaKolom,' from tblProses where kolom1="',namaPelaku,'" into @angka');
40. prepare query from @query;
41. execute query;
42. deallocate prepare query;
43. select @angka into angka;
44. set @query =concat('update
tblProses set ',namaKolom,'= (',angka, '-',minim,') where kolom1="',
namaPelaku ,'"');
45. prepare query from @query;
46. execute query;
48. end if;
49. set k = k+1;
50. end while;
51. close kursorNamaKolom;
52. set i = i+1;
53. end while;
54. close kursorNilaiMinim; 55. close kursorNamaBaris; 56. select * from tblProses; 57. end;
The main meaning of codes above is about normalizing rows in table. In
row 1, it is code to create stored procedure spNorRow(). In row 29 to 55, it is code
to substract costs in each row based on its minimal cost which has been found in
the store procedure spFindMinimBaris(). It is for getting 0 cost in each row.
dbSkripsi.sql
1. create procedure spFindMinimKolom() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
10. declare namaKolom varchar(100); 11. declare namaPelaku varchar(100); 12. declare namaKolomPelaku varchar(100); 13. declare angka int;
14. declare jmlPelaku int; 15. declare x int default 0;
16. declare tempTotalMinim int default 0; 17. declare totB,totK int;
18. declare kursorNamaKolom cursor for
19. select column_name
20. from information_schema.columns 21. where table_name='tblProses'; 22. declare kursorNamaBaris cursor for 23. select kolom1 from tblProses; 24. declare kursorNilaiMinim cursor for 25. select * from tblMinimBaris;
26. select '' as '==========Minim Kolom=========='; 27. select count(kolom1) from tblProses into jmlPelaku; 28. select count(*)
29. from information_schema.columns
31. open kursorNamaKolom;
32. while i <= jmlKolom do
33. fetch kursorNamaKolom into namaKolom;
34. if (i > 1) then
35. set j = 1;
36. set minim = 999999999;
37. open kursorNamaBaris;
38. while j <= jmlPelaku do
39. fetch kursorNamaBaris into
namaPelaku;
40. set @query = concat('select '
,namaKolom,' from tblProses where kolom1 ="',namaPelaku,'" into @angka');
41. prepare query from @query;
42. execute query;
43. deallocate prepare query;
44. select @angka into angka;
45. set temp = angka;
46.
47. if(minim = 999999999) then
48. set minim = temp;
49. elseif(angka <= minim ) then
50. set minim = angka;
51. end if;
52. set j = j+1;
53. end while;
54. insert into tblMinimKolom
values(minim);
55. close kursorNamaBaris;
56. end if;
57. set i =i+1;
58. end while;
59. close kursorNamaKolom;
60. select * from tblMinimKolom;
61. select sum(nilaiMinimKolom) from tblMinimKolom into totK; 62. select sum(nilaiMinimBaris) from tblMinimBaris into totB; 63. set tempTotalMinim = totB+totK;
64. update tblTotalNilaiMinim set totalNilaiMinim = tempTotalMinim;
65. end;
The main meaning of the codes above is to find minimum cost each
column. In row 1, it is code to create stored procedure spFindMinimKolom().
Codes in row 31 to 59, it is about finding the minimum cost each column by
looping costs in column to rows. Each minimum cost in column is added to the
dbSkripsi.sql
1. create procedure spNorCol() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
10. declare namaKolom varchar(100); 11. declare namaPelaku varchar(100); 12. declare namaKolomPelaku varchar(100); 13. declare angka int;
14. declare jmlPelaku int; 15. declare x int default 0;
16. declare tempTotalMinim int default 0; 17. declare totB,totK int;
18. declare kursorNamaKolom cursor for
19. select column_name
20. from information_schema.columns 21. where table_name='tblProses'; 22. declare kursorNamaBaris cursor for 23. select kolom1 from tblProses; 24. declare kursorNilaiMinim cursor for 25. select * from tblMinimKolom;
26. select '' as '==========Normalisasi Kolom=========='; 27. select count(kolom1) from tblProses into jmlPelaku; 28. select count(*)
29. from information_schema.columns
30. where table_name = 'tblProses' into jmlKolom; 31. open kursorNamaKolom;
32. open kursorNilaiMinim; 33. while i <= jmlKolom do
34. fetch kursorNamaKolom into namaKolom;
35. if (i > 1) then
36. fetch kursorNilaiMinim into minim;
37. set j = 1;
38. open kursorNamaBaris;
39. while j <= jmlPelaku do
40. fetch kursorNamaBaris into
namaPelaku;
41. set @query = concat('select
',namaKolom,' from tblProses where kolom1="',namaPelaku, '" into @angka');
42. prepare query from @query;
43. execute query;
44. deallocate prepare query;
46. set @query = concat('update tblProses set ',namaKolom,' = (',angka,'-',minim,') where kolom1 = "',namaPelaku,'"');
47. prepare query from @query;
48. execute query;
49. deallocate prepare query;
50. set j = j+1;
51. end while;
52. close kursorNamaBaris;
53. end if;
54. set i =i+1;
55. end while;
56. close kursorNilaiMinim; 57. close kursorNamaKolom;
58. select * from tblProses; 59. end;
The main meaning of codes above is about normalizing columns in table.
In row 1, it is code to create stored procedure spNorCol(). In row 31 to 57, it is
code to substract costs in each column based on its minimal cost which has been
found in the store procedure spFindMinimKolom(). It is for getting 0 cost in each
column.
dbSkripsi.sql
1. create procedure spFindNol() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
10. declare namaKolom varchar(100); 11. declare namaPelaku varchar(100); 12. declare namaKolomPelaku varchar(100); 13. declare angka int;
14. declare jmlPelaku int; 15. declare x int;
16. declare nmPelaku varchar(100); 17. declare nmPekerjaan varchar(100); 18. declare tarifx int;
19. declare kursorNamaKolom cursor for
20. select column_name
23. declare kursorNamaBaris cursor for 24. select kolom1 from tblProses; 25. declare kursorNilaiMinim cursor for 26. select * from tblMinimBaris;
27. select count(kolom1) from tblProses into jmlPelaku; 28. select count(*)
29. from information_schema.columns
30. where table_name = 'tblProses' into jmlKolom; 31. select '' as '==========Find 0=========='; 32. open kursorNamaBaris;
33. open kursorNilaiMinim; 34. while i <= jmlPelaku do
35. fetch kursorNamaBaris into namaPelaku;
36. set k = 1;
37. set x = 0;
38. open kursorNamaKolom;
39. while k <= jmlKolom do
40. fetch kursorNamaKolom into
namaKolom;
41. if(k>1) then
42. set @query =
concat('select count(*) into @jmlData from
tblProses where kolom1 = "',namapelaku,'" and ', namaKolom,' = 0');
43. prepare query from
@query;
44. execute query;
45. deallocate prepare
query;
46. if(@jmlData!=0) then
47. set @query =
concat('select "',namaPelaku,'" , ','"',namaKolom,'" ',',',namaKolom ,' into @nmPelaku, @nmPekerjaan, @tarifx from tblProses where kolom1 = "', namapelaku,'"and ',namaKolom,' = 0');
48. prepare query from
@query;
49. execute query;
50. deallocate prepare
51. select @nmPelaku into nmPelaku;
52. select
@nmPekerjaan into nmPekerjaan;
53. select @tarifx
into tarifx;
54. insert into
tblTempHasil values(nmPelaku, nmPekerjaan, tarifx);
55. end if;
56. end if;
57. set k = k+1;
58. end while;
59. close kursorNamaKolom;
60. set i = i+1;
61. end while;
62. close kursorNamaBaris; 63. select * from tblTempHasil; 64. end;
The main meaning of codes above is about finding 0 costs in table. In row
32 to 62, it is code to find the 0 costs in table by looping the data from the row to
column. If 0 cost is found, the row's name and column's name are inserted into
table tblTempHasil. Table tblTempHasil contains worker, job, and 0 cost data. The
data which contained in the table is data whose cost is 0.
dbSkripsi.sql
1. create procedure spSortTableTemp() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int; 10. declare jmlPelaku int;
11. declare namaKolom varchar(100); 12. declare namaBaris varchar(100); 13. declare angka int;
14. declare jmlDataTempHasil int; 15. declare x,y,z int;
16. declare jmlBaris int;
18. declare hasilPekerjaan varchar(100); 19. declare hasilTarif varchar(100); 20. declare tarifAsli int;
21. declare sortPelaku varchar(100); 22. declare nmPelaku varchar(100); 23. declare nmPekerjaan varchar(100); 24. declare tarifx int;
25. declare status varchar(100); 26. declare tmpPelaku varchar(100); 27. declare tmpPekerjaan varchar(100); 28. declare jmlStatus int default 1; 29. declare kursorNamaKolom cursor for
30. select column_name
31. from information_schema.columns 32. where table_name='tblProses'; 33. declare kursorNamaBaris cursor for 34. select kolom1 from tblProses; 35. declare kursorNilaiMinim cursor for 36. select * from tblMinimBaris; 37. declare kursorTempHasil cursor for 38. select * from tblTempHasil;
39. declare kursorSortingTempHasil cursor for
40. select namaPelaku
41. from tblTempHasil
42. group by namaPelaku
43. order by count(namaPekerjaan) desc, namaPelaku asc; 44. select count(*) from tblProses into jmlBaris;
45. select count(*) from tblTempHasil into jmlDataTempHasil; 46. select count(*)
47. from information_schema.columns
48. where table_name = 'tblProses' into jmlKolom; 49. set status= 'salah';
50. select '' as '==========Sort Data From Max Pekerjaan==========';
51. open kursorSortingTempHasil; 52. while i<= jmlBaris do
53. fetch kursorSortingTempHasil into sortPelaku;
54. set j = 1;
55. open kursorTempHasil;
56. while j<= jmlDataTempHasil do
57. fetch kursorTempHasil into nmPelaku,
nmPekerjaan, tarifx;
58. if(nmPelaku = sortPelaku) then
59. insert into tblSortTempHasil
values (nmPelaku, nmPekerjaan,tarifx);
60. end if;
61. set j = j+1;
62. end while;
63. close kursorTempHasil;
65. end while;
66. close kursorSortingTempHasil; 67. select * from tblSortTempHasil; 68. end;
The main meaning of codes above is about sorting the 0 cost data in table.
In row 52 to 66, it is code to sort data whose cost is 0 in table. The data is sorted
based on the most jobs option taken by one worker.
dbSkripsi.sql
1. create procedure spInputIntoTableHasil() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int; 10. declare jmlPelaku int;
11. declare namaKolom varchar(100); 12. declare namaBaris varchar(100); 13. declare angka int;
14. declare jmlDataTempHasil int; 15. declare x,y,z int;
16. declare jmlBaris int;
17. declare hasilNama varchar(100); 18. declare hasilPekerjaan varchar(100); 19. declare hasilTarif varchar(100); 20. declare tarifAsli int;
21. declare sortPelaku varchar(100); 22. declare nmPelaku varchar(100); 23. declare nmPekerjaan varchar(100); 24. declare tarifx int;
25. declare status varchar(100); 26. declare tmpPelaku varchar(100); 27. declare tmpPekerjaan varchar(100); 28. declare jmlStatus int default 1; 29. declare kursorNamaKolom cursor for
30. select column_name
31. from information_schema.columns 32. where table_name='tblProses'; 33. declare kursorNamaBaris cursor for
34. select distinct(namaPelaku) from tblSortTempHasil; 35. declare kursorNilaiMinim cursor for
39. declare kursorMostPekerjaan cursor for
40. select namaPelaku
41. from tblSortTempHasil
42. group by namaPelaku
43. having count(namaPelaku)>1
44. order by count(namaPekerjaan) desc, namaPelaku asc; 45. select count(*) from tblProses into jmlBaris;
46. select count(*) from tblTempHasil into jmlDataTempHasil; 47. select count(*)
48. from information_schema.columns
49. where table_name = 'tblProses' into jmlKolom; 50. set status= 'salah';
51. select '' as '==========Input Into Table Hasil=========='; 52. open kursorNamaBaris;
53. while i<=jmlBaris do
54. fetch kursorNamaBaris into namaBaris;
55. set x = 0;
56. set j = 1;
57. open kursorNamaKolom;
58. while j<=jmlKolom do
59. fetch kursorNamaKolom into namaKolom;
60. if(j>1) then
61. set y = 0;
62. set k = 1;
63. open kursorSortTempHasil;
64. while k<= jmlDataTempHasil do
65. fetch kursorSortTempHasil into nmPelaku,
nmPekerjaan, tarifx;
66. select c.tarif
67. from tblRelasi as c,
68. tblPelaku as a,
69. tblPekerjaan as b
70. where c.idPelaku = a.idPelaku and
71. c.idPekerjaan = b.idPekerjaan and
72. a.namaPelaku = namaBaris and
73. b.namaPekerjaan = namaKolom
74. into angka;
75. if(namaBaris=nmPelaku and namaKolom =
nmPekerjaan) then
76. select count(*) from tblHasil where
namaPelaku = namaBaris into x;
77. select count(*) from tblHasil where
namaPekerjaan=namaKolom into y;
78. if(x=0) then
79. if(y=0) then
80. insert into tblHasil
values (namaBaris, namaKolom , angka);
81. end if;
82. end if;
84. set k = k+1;
85. end while;
86. close kursorSortTempHasil;
87. end if;
88. set j = j+1;
89. end while;
90. close kursorNamaKolom;
91. set i = i+1;
92. end while;
93. close kursorNamaBaris;
94. select count(counted) into jmlData from
95. (
96. select namaPelaku as counted
97. from tblSortTempHasil
98. group by namaPelaku
99. having count(namaPelaku)>1 100. order by count(namaPekerjaan) desc 101. ) as Banyak;
102. set i =1; 103. set j =1;
104. open kursorMostPekerjaan; 105. while i<= jmlData do
106. fetch kursorMostPekerjaan into sortPelaku;
107. set j = 1;
108. open kursorSortTempHasil;
109. while j <= jmlDataTempHasil do
110. fetch kursorSortTempHasil into
nmPelaku, nmPekerjaan, tarifx;
111. if(nmPelaku = sortPelaku) then
112. insert into
tblMostPekerjaan values(nmPelaku, nmPekerjaan);
113. end if;
114. set j = j+1;
115. end while;
116. close kursorSortTempHasil;
117. set i = i+1;
118. end while;
119. close kursorMostPekerjaan;
120. select '+=============================+'; 121. select * from tblHasil;
122. end;
The main meaning of codes above is about inserting data whose cost is 0
into table to be the result. In row 52 to 119, it is code to insert data whose cost is 0
into table tblHasil. The data in table tblHasil must be checked to next process to
dbSkripsi.sql
1. create procedure spCheckMatching() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
10. declare namaKolom varchar(100); 11. declare namaBaris varchar(100); 12. declare angka int;
13. declare jmlDataTempHasil int; 14. declare jmlDataHasil int; 15. declare x,y int;
16. declare jmlBaris int;
17. declare hasilNama varchar(100); 18. declare hasilPekerjaan varchar(100); 19. declare hasilTarif varchar(100); 20. declare tarifAsli int;
21. declare nmPelaku varchar(100); 22. declare nmPekerjaan varchar(100); 23. declare tarifx int;
24. declare tmpPelaku varchar(100); 25. declare tmpPekerjaan varchar(100); 26. declare tmpTarif int;
27. declare hslPelaku varchar(100); 28. declare hslPekerjaan varchar(100); 29. declare hslTarif int;
30. declare maksBanyakPekerjaan int; 31. declare status varchar(10);
32. declare kursorSortTemp cursor for 33. select * from tblSortTempHasil; 34. declare kursorHasil cursor for
35. select * from tblHasil;
36. declare kursorMostPekerjaan cursor for 37. select * from tblMostPekerjaan;
38. select count(*) from tblTempHasil into jmlDataTempHasil; 39. select count(*) from tblHasil into jmlDataHasil; 40. select count(*) from tblMostPekerjaan into jmlData; 41. select max(counted) into maksBanyakPekerjaan
42. from (
43. select count(namaPekerjaan) as counted
44. from tblTempHasil
45. group by namaPelaku
46. ) as MAXIMUM;
47. select '' as '==========Check Matching=========='; 48. open kursorMostPekerjaan;
50. fetch kursorMostPekerjaan into tmpPelaku, tmpPekerjaan;
51. set j = 1;
52. open kursorHasil;
53. while j<= jmlDataHasil do
54. fetch kursorHasil into hslPelaku,
hslPekerjaan, hslTarif;
55. select c.tarif
56. from tblRelasi as c,
57. tblPelaku as a,
58. tblPekerjaan as b
59. where c.idPelaku = a.idPelaku and
60. c.idPekerjaan = b.idPekerjaan
and
61. a.namaPelaku = tmpPelaku and
62. b.namaPekerjaan = tmpPekerjaan
63. into angka;
64. select count(*) from tblHasil where
namaPekerjaan=tmpPekerjaan into y;
65. if(hslPelaku = tmpPelaku) then
66. if(y=0) then
67. select concat(hslPelaku,
' dan ', hslPekerjaan, '>>>',tmpPelaku,' dan ', tmpPekerjaan) as '';
68. set @query = concat(
69. 'update tblHasil
set tarif = ', angka,
70. ', namaPekerjaan =
"', tmpPekerjaan,
71. '" where
namaPelaku = "', tmpPelaku,'"' );
72. prepare query from
@query;
73. execute query;
74. deallocate prepare
query;
75. call
spInputIntoTableHasil();
76. end if;
77. end if;
78. set j = j+1;
79. end while;
80. close kursorHasil;
81. set i = i+1;
82. end while;
The main meaning of codes above is about checking the result that it is
optimum or not. In row 48 to 83, it is code to check data in table tblHasil (table
result) that it has been optimum or must be rematched to get the optimum result.
1. dbSkripsi.sql
2. create procedure spFindSmallest() 3. begin
4. declare i,j,k int default 1;
5. declare minim int default 999999999; 6. declare temp int default 0;
7. declare totalMinim int default 0; 8. declare jmlData int;
9. declare totalData int; 10. declare jmlKolom int;
11. declare namaKolom varchar(100); 12. declare namaPelaku varchar(100); 13. declare namaKolomPelaku varchar(100); 14. declare angka int;
15. declare jmlPelaku int; 16. declare x,y,z int;
17. declare xPelaku varchar(100); 18. declare xPekerjaan varchar(100); 19. declare jmlXPelaku int default 0; 20. declare jmlXPekerjaan int default 0; 21. declare xxPelaku varchar(100);
22. declare kursorNamaKolom cursor for
23. select column_name
24. from information_schema.columns 25. where table_name='tblProses'; 26. declare kursorNamaBaris cursor for 27. select kolom1 from tblProses; 28. declare kursorNilaiMinim cursor for 29. select * from tblMinimBaris;
30. select count(kolom1) from tblProses into jmlPelaku; 31. select count(*)
32. from information_schema.columns
33. where table_name = 'tblProses' into jmlKolom; 34. select '' as '==========Find Smallest=========='; 35. delete from tblMinimBaris;
36. open kursorNamaBaris;
37. while i <= jmlPelaku do
38. fetch kursorNamaBaris into xPelaku;
39. set @query= concat('select count(*) into
@x from tblTempHasil where namaPelaku = "', xPelaku,'"');
40. prepare query from @query;
41. execute query;
42. deallocate prepare query;
44. select xPelaku, x;
45. set @query= concat('select namaPelaku into
@xxPelaku from tblTempHasil where namaPelaku = "',xPelaku,'" group by namaPelaku having count(namaPelaku)>1');
46. prepare query from @query;
47. execute query;
48. deallocate prepare query;
49. select @xxPelaku into xxPelaku;
50. set j = 1;
51. set minim = 999999999;
52. open kursorNamaKolom;
53. while j <= jmlKolom do
54. fetch kursorNamaKolom
into xPekerjaan;
55. if (j > 1) then
56. select count(*)
into y from
tblTempHasil where namaPekerjaan = xPekerjaan;
57. set @query=
concat('select count(*) into @z from tblProses where ',xPekerjaan ,' = 0 and
kolom1 !=
"',xxPelaku,'" ');
58. prepare query from
@query;
59. execute query;
60. deallocate prepare
query;
61. select @z into z;
62. if(x<=1) then
63. if(z<=1) then
64. set @query =
concat('select ', xPekerjaan, ' from tblProses where kolom1 = "', xPelaku,'" into @angka');
65. prepare query from
@query;
66. execute query;
67. deallocate prepare
query;
68. select @angka into
69. set temp = angka;
70. if(minim =
999999999) then
71. set minim = temp;
72. elseif(angka <=
minim ) then
73. set minim = angka;
74. end if;
75. end if;
76. end if;
77. end if;
78. set j = j+1;
79. end while;
80. insert into tblMinimBaris
values(minim);
81. close kursorNamaKolom;
82. set i = i+1;
83. end while;
84. close kursorNamaBaris;
85. select distinct(min(nilaiMinimBaris)) from tblMinimBaris into z;
86. delete from tblMinimBaris;
87. insert into tblMinimBaris values(z);
88. update tblTotalNilaiMinim set totalNilaiMinim = totalNilaiMinim + z;
89. select * from tblMinimBaris; 90. end;
The main meaning of codes above is about finding the smallest cost in
table. In row 36 to 84, it is code to find the smallest cost in table by looping from
rows to columns where the rows and column that are looped have not 0 cost.
Then, the smallest cost is inserted into table tblMinimbaris. The data in table
tblMinimBaris should has been deleted before.
dbSkripsi.sql
1. create procedure spNorMatch() 2. begin
3. declare i,j,k int default 1; 4. declare minim int default 0; 5. declare temp int default 0;
6. declare totalMinim int default 0; 7. declare jmlData int;
8. declare totalData int; 9. declare jmlKolom int;
13. declare angka int; 14. declare jmlPelaku int; 15. declare x,y,z int;
16. declare xPelaku varchar(100); 17. declare xPekerjaan varchar(100); 18. declare xxPelaku varchar(100); 19. declare kursorNamaKolom cursor for
20. select column_name
21. from information_schema.columns 22. where table_name='tblProses'; 23. declare kursorNamaBaris cursor for 24. select kolom1 from tblProses; 25. declare kursorNilaiMinim cursor for 26. select * from tblMinimBaris;
27. select count(kolom1) from tblProses into jmlPelaku; 28. select count(*)
29. from information_schema.columns
30. where table_name = 'tblProses' into jmlKolom; 31. select * from tblMinimBaris into minim;
32. open kursorNamaBaris;
33. while i <= jmlPelaku do
34. fetch kursorNamaBaris into xPelaku;
35. set @query= concat('select count(*) into @x from tblTempHasil where namaPelaku = "',xPelaku,'"');
36. prepare query from @query;
37. execute query;
38. deallocate prepare query;
39. select @x into x;
40. set @query= concat('select namaPelaku into
@xxPelaku from tblTempHasil where namaPelaku = "',xPelaku,'" group by namaPelaku having
count(namaPelaku)>1');
41. prepare query from @query;
42. execute query;
43. deallocate prepare query;
44. select @xxPelaku into xxPelaku;
45. set k = 1;
46. open kursorNamaKolom;
47. while k <= jmlKolom do
48. fetch kursorNamaKolom into
xPekerjaan;
49. if (k > 1) then
50. select count(*) from
tblTempHasil where namaPekerjaan = xPekerjaan into y;
51. set@query=concat('select
kolom1!="',xxPelaku,'" ');
52. prepare query from
@query;
53. execute query;
54. deallocate prepare
query;
55. select @z into z;
56. if(x<=1) then
57. if(z<=1) then
58. set @query =
oncat('select ', xPekerjaan, ' from tblProses where kolom1 = "', xPelaku,'" into @angka');
59. prepare query from
@query;
60. execute query;
61. deallocate prepare
query;
62. select @angka into
angka;
63. set @query =
concat('update tblProses set ', xPekerjaan,' = (', angka,'-',minim,') where kolom1 = "',xPelaku,'"');
64. prepare query from
@query;
65. execute query;
66. deallocate prepare
query;
67. end if;
68. else
69. if(z>1) then
70. set @query =
concat('select ', xPekerjaan, ' from tblProses where kolom1 = "', xPelaku,'" into @angka');
71. prepare query from
@query;
72. execute query;
73. deallocate prepare
74. select @angka into angka;
75. set @query =
concat('update tblProses set ', xPekerjaan,' = (',angka,'+', minim, ') where kolom1 = "', xPelaku,'"');
76. prepare query from
@query;
77. execute query;
78. deallocate prepare
query;
79. end if;
80. end if;
81. end if;
82. set k = k+1;
83. end while;
84. close kursorNamaKolom;
85. set i = i+1;
86. end while;
87. close kursorNamaBaris; 88. select * from tblProses; 89. end;
The main meaning of codes above is about normalizing table result which
is not optimum. In row 32 to 87, it is code to normalize rows and columns in table
tblHasil (table result), because the data in it is not optimum. The costs are in table
is substracted by the smallest cost which has been stored in the table
tblMinimBaris before and the normalization process is done by normalizing the
rows and columns in the table.
5.2
Testing
For the test, there will be three examples data.
The first example, user inputs
4
in textfield and klik
Process
button to
process it.
From the user input, it will produce data as much as
4.
The output from the first sample data.
The second example, user inputs
5
in textfield and klik
Process
button to
process it.
Illustration 5.5: Second Input Sample Illustration 5.3: First
Data Sample
From the user input, it will produce data as much as
5.
The output from the second sample data.
The third example, user inputs
6
in textfield and klik
Process
button to
process it.
Illustration 5.6: Second Data Sample
Illustration 5.7: Second Output Sample
From the user input, it will produce data as much as
5.
The output from the third sample data.
From the three examples above, the program is running well.
Illustration 5.9: Third Sample Data