main.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /****************************************************************************
  2. *
  3. * MODULE: db.createdb
  4. * AUTHOR(S): Radim Blazek <radim.blazek gmail.com> (original contributor)
  5. * Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
  6. * PURPOSE: create a new empty database
  7. * COPYRIGHT: (C) 2002-2006 by the GRASS Development Team
  8. *
  9. * This program is free software under the GNU General Public
  10. * License (>=v2). Read the file COPYING that comes with GRASS
  11. * for details.
  12. *
  13. *****************************************************************************/
  14. #include <stdlib.h>
  15. #include <grass/dbmi.h>
  16. #include <grass/gis.h>
  17. #include <grass/glocale.h>
  18. struct
  19. {
  20. char *driver, *database;
  21. } parms;
  22. /* function prototypes */
  23. static void parse_command_line(int, char **);
  24. int main(int argc, char **argv)
  25. {
  26. dbDriver *driver;
  27. dbHandle handle;
  28. int stat;
  29. parse_command_line(argc, argv);
  30. driver = db_start_driver(parms.driver);
  31. if (driver == NULL)
  32. G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
  33. db_init_handle(&handle);
  34. db_set_handle(&handle, parms.database, NULL);
  35. stat = db_create_database(driver, &handle);
  36. db_shutdown_driver(driver);
  37. exit(stat == DB_OK ? EXIT_SUCCESS : EXIT_FAILURE);
  38. }
  39. static void parse_command_line(int argc, char **argv)
  40. {
  41. struct Option *driver, *database;
  42. struct GModule *module;
  43. /* Initialize the GIS calls */
  44. G_gisinit(argv[0]);
  45. driver = G_define_standard_option(G_OPT_DB_DRIVER);
  46. driver->options = db_list_drivers();
  47. driver->required = YES;
  48. driver->answer = (char *) db_get_default_driver_name();
  49. database = G_define_standard_option(G_OPT_DB_DATABASE);
  50. database->required = YES;
  51. /* Set description */
  52. module = G_define_module();
  53. G_add_keyword(_("database"));
  54. G_add_keyword(_("attribute table"));
  55. G_add_keyword(_("SQL"));
  56. module->description = _("Creates an empty database.");
  57. if (G_parser(argc, argv))
  58. exit(EXIT_FAILURE);
  59. parms.driver = driver->answer;
  60. parms.database = database->answer;
  61. }