intlbld.e 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * The contents of this file are subject to the Interbase Public
  3. * License Version 1.0 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy
  5. * of the License at http://www.Inprise.com/IPL.html
  6. *
  7. * Software distributed under the License is distributed on an
  8. * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  9. * or implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code was created by Inprise Corporation
  13. * and its predecessors. Portions created by Inprise Corporation are
  14. * Copyright (C) Inprise Corporation.
  15. *
  16. * All Rights Reserved.
  17. * Contributor(s): ______________________________________.
  18. */
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. //#include "../jrd/common.h"
  23. #include "ibase.h"
  24. /* typedef char TEXT; */
  25. #define FINI_OK 0
  26. #define FINI_ERROR 44
  27. /*
  28. ** Intlbld.e International version of Empbuild.e. Default database
  29. ** name was changed to 'intlemp.fdb'. Two of the files
  30. ** executed as ISQL input files were modified: intlddl.sql
  31. ** and intldml.sql are used by this program.
  32. **
  33. ** GPRE with manual switch, since it creates the database
  34. ** This program then calls isql with various input files
  35. ** It installs the blobs and arrays.
  36. ** Usage: empbuild <db name>
  37. */
  38. static int addlang (void);
  39. static int addjob (void);
  40. static int addproj (void);
  41. static int addqtr (void);
  42. static TEXT Db_name[128];
  43. static FILE *Fp;
  44. EXEC SQL SET SQL DIALECT 3;
  45. EXEC SQL INCLUDE SQLCA;
  46. EXEC SQL SET DATABASE DB = COMPILETIME "intlbuild.fdb" RUNTIME :Db_name;
  47. int main (
  48. int argc,
  49. char *argv[])
  50. {
  51. /**************************************
  52. *
  53. * m a i n
  54. *
  55. **************************************
  56. *
  57. * Functional description
  58. *
  59. **************************************/
  60. TEXT cmd [140];
  61. if (argc > 1)
  62. strcpy (Db_name, argv[1]);
  63. else
  64. strcpy (Db_name, "intlemp.fdb");
  65. /* Create the database */
  66. printf ("creating database %s\n", Db_name);
  67. sprintf (cmd, "CREATE DATABASE \"%s\" DEFAULT CHARACTER SET ISO8859_1", Db_name);
  68. gds__trans = 0;
  69. EXEC SQL EXECUTE IMMEDIATE :cmd;
  70. if (SQLCODE)
  71. {
  72. isc_print_status (gds__status);
  73. exit (FINI_ERROR);
  74. }
  75. gds__trans = 0;
  76. EXEC SQL DISCONNECT ALL;
  77. if (SQLCODE)
  78. {
  79. isc_print_status (gds__status);
  80. exit (FINI_ERROR);
  81. }
  82. /* ddl and dml file names are different for international */
  83. printf ("Creating tables\n");
  84. sprintf (cmd, "isql %s -q -i intlddl.sql", Db_name);
  85. if (system (cmd))
  86. {
  87. printf ("Couldn't create tables \n");
  88. exit (FINI_ERROR);
  89. }
  90. printf ("Turning off indices and triggers \n");
  91. sprintf (cmd, "isql %s -i indexoff.sql", Db_name);
  92. system (cmd);
  93. printf ("Loading column data\n");
  94. sprintf (cmd, "isql %s -ch ISO8859_1 -i intldml.sql", Db_name);
  95. system (cmd);
  96. printf ("Turning on indices and triggers \n");
  97. sprintf (cmd, "isql %s -i indexon.sql", Db_name);
  98. system (cmd);
  99. EXEC SQL CONNECT DB;
  100. if (SQLCODE)
  101. {
  102. isc_print_status (gds__status);
  103. exit (FINI_ERROR);
  104. }
  105. EXEC SQL SET TRANSACTION;
  106. printf ("Loading Language blobs\n");
  107. addlang();
  108. printf ("Loading Job blobs\n");
  109. addjob();
  110. printf ("Loading project blobs \n");
  111. addproj();
  112. printf ("Loading quarter arrays \n");
  113. addqtr();
  114. exit (FINI_OK);
  115. }
  116. static int addlang (void)
  117. {
  118. /**************************************
  119. *
  120. * a d d l a n g
  121. *
  122. **************************************
  123. *
  124. * Functional description
  125. * Add language array to 'job' table.
  126. *
  127. **************************************/
  128. TEXT job_code[6], job_country[16];
  129. TEXT line[81];
  130. TEXT lang_array[5][16];
  131. int i, job_grade, rec_cnt = 0;
  132. EXEC SQL SET TRANSACTION;
  133. EXEC SQL WHENEVER SQLERROR GO TO Error;
  134. Fp = fopen ("lang.inp", "r");
  135. while (fgets (line, 100, Fp) != NULL)
  136. {
  137. sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
  138. for (i = 0; i < 5; i++)
  139. {
  140. if (fgets (line, 100, Fp) == NULL)
  141. break;
  142. strcpy (lang_array [i], line);
  143. }
  144. EXEC SQL
  145. UPDATE job
  146. SET language_req = :lang_array
  147. WHERE job_code = :job_code AND
  148. job_grade = :job_grade AND
  149. job_country = :job_country;
  150. if (SQLCODE == 0)
  151. rec_cnt++;
  152. else
  153. {
  154. printf ("Input error -- no job record with key: %s %d %s\n",
  155. job_code, job_grade, job_country);
  156. }
  157. }
  158. EXEC SQL COMMIT;
  159. printf ("Added %d language arrays.\n", rec_cnt);
  160. fclose (Fp);
  161. return (0);
  162. Error:
  163. printf ("SQLCODE=%d\n", SQLCODE);
  164. isc_print_status (gds__status);
  165. return (1);
  166. }
  167. static int addjob (void)
  168. {
  169. /**************************************
  170. *
  171. * a d d j o b
  172. *
  173. **************************************
  174. *
  175. * Functional description
  176. * Add job description blobs.
  177. *
  178. **************************************/
  179. TEXT job_code[6];
  180. TEXT line[82], job_country[16];
  181. int len;
  182. ISC_QUAD job_blob;
  183. int job_grade, rec_cnt = 0;
  184. EXEC SQL SET TRANSACTION;
  185. EXEC SQL WHENEVER SQLERROR GO TO Error;
  186. EXEC SQL DECLARE be CURSOR FOR
  187. INSERT BLOB job_requirement INTO job;
  188. Fp = fopen ("job.inp", "r");
  189. while (fgets (line, 100, Fp) != NULL)
  190. {
  191. EXEC SQL OPEN be INTO :job_blob;
  192. sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
  193. while (fgets (line, 100, Fp) != NULL)
  194. {
  195. if (*line == '\n')
  196. break;
  197. len = strlen (line);
  198. EXEC SQL INSERT CURSOR be VALUES (:line INDICATOR :len);
  199. }
  200. EXEC SQL CLOSE be;
  201. EXEC SQL
  202. UPDATE job
  203. SET job_requirement = :job_blob
  204. WHERE job_code = :job_code AND
  205. job_grade = :job_grade AND
  206. job_country = :job_country;
  207. if (SQLCODE == 0)
  208. rec_cnt++;
  209. else
  210. {
  211. printf ("Input error -- no job record with key: %s %d %s\n",
  212. job_code, job_grade, job_country);
  213. }
  214. }
  215. EXEC SQL COMMIT;
  216. printf ("Added %d job requirement descriptions.\n", rec_cnt);
  217. fclose (Fp);
  218. return (0);
  219. Error:
  220. printf ("SQLCODE=%d\n", SQLCODE);
  221. isc_print_status (gds__status);
  222. return (1);
  223. }
  224. static int addproj (void)
  225. {
  226. /**************************************
  227. *
  228. * a d d p r o j
  229. *
  230. **************************************
  231. *
  232. * Functional description
  233. * Add project description blobs.
  234. *
  235. **************************************/
  236. TEXT proj_id[6];
  237. TEXT line[82];
  238. int len;
  239. ISC_QUAD proj_blob;
  240. int rec_cnt = 0;
  241. EXEC SQL SET TRANSACTION;
  242. EXEC SQL WHENEVER SQLERROR GO TO Error;
  243. EXEC SQL DECLARE bd CURSOR FOR
  244. INSERT BLOB proj_desc INTO project;
  245. Fp = fopen ("proj.inp", "r");
  246. while (fgets (line, 100, Fp) != NULL)
  247. {
  248. EXEC SQL OPEN bd INTO :proj_blob;
  249. sscanf (line, "%s", proj_id);
  250. while (fgets (line, 100, Fp) != NULL)
  251. {
  252. if (*line == '\n')
  253. break;
  254. len = strlen (line);
  255. EXEC SQL INSERT CURSOR bd VALUES (:line INDICATOR :len);
  256. }
  257. EXEC SQL CLOSE bd;
  258. EXEC SQL
  259. UPDATE project
  260. SET proj_desc = :proj_blob
  261. WHERE proj_id = :proj_id;
  262. if (SQLCODE == 0)
  263. rec_cnt++;
  264. else
  265. {
  266. printf ("Input error -- no project record with key: %s\n", proj_id);
  267. }
  268. }
  269. EXEC SQL COMMIT;
  270. printf ("Added %d project descriptions.\n", rec_cnt);
  271. fclose (Fp);
  272. return (0);
  273. Error:
  274. printf ("SQLCODE=%d\n", SQLCODE);
  275. isc_print_status (gds__status);
  276. return (1);
  277. }
  278. static int addqtr (void)
  279. {
  280. /**************************************
  281. *
  282. * a d d q t r
  283. *
  284. **************************************
  285. *
  286. * Functional description
  287. * Add project quarterly head-count array to 'proj_dept_budget' table.
  288. *
  289. **************************************/
  290. TEXT proj_id[6], dept_no[4];
  291. int yr;
  292. TEXT line[81];
  293. int hcnt[4];
  294. int rec_cnt = 0;
  295. EXEC SQL SET TRANSACTION;
  296. EXEC SQL WHENEVER SQLERROR GO TO Error;
  297. Fp = fopen ("qtr.inp", "r");
  298. while (fgets (line, 100, Fp) != NULL)
  299. {
  300. sscanf (line, "%d %s %s %d %d %d %d", &yr, proj_id, dept_no,
  301. &hcnt[0], &hcnt[1], &hcnt[2], &hcnt[3]);
  302. EXEC SQL
  303. UPDATE proj_dept_budget
  304. SET quart_head_cnt = :hcnt
  305. WHERE fiscal_year = :yr AND proj_id = :proj_id AND dept_no = :dept_no;
  306. if (SQLCODE == 0)
  307. rec_cnt++;
  308. else
  309. {
  310. printf ("Input error -- no job record with key: %d %s %s\n",
  311. yr, proj_id, dept_no);
  312. }
  313. }
  314. EXEC SQL COMMIT RELEASE;
  315. printf ("Added %d quarter arrays.\n", rec_cnt);
  316. fclose (Fp);
  317. return (0);
  318. Error:
  319. printf ("SQLCODE=%d\n", SQLCODE);
  320. isc_print_status (gds__status);
  321. return (1);
  322. }