home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / database / sybase / 279 < prev    next >
Encoding:
Text File  |  1992-11-09  |  2.6 KB  |  99 lines

  1. Path: sparky!uunet!kddlab!jcpltyo!ohayon
  2. From: ohayon@jcpltyo.JCPL.CO.JP (Tsiel Ohayon)
  3. Newsgroups: comp.databases.sybase
  4. Subject: Re: Hiding a password while dumping
  5. Message-ID: <94@jcpltyo.JCPL.CO.JP>
  6. Date: 9 Nov 92 23:33:17 GMT
  7. References: <1688@anagld.analytics.com> <93@jcpltyo.JCPL.CO.JP>
  8. Organization: James Capel Pacific Limited, Tokyo Japan
  9. Lines: 88
  10.  
  11.  
  12. After recieving a few E-mails, I'm posting the following C program
  13. which dumps a Sybase database. It is not optimal but works
  14. great.
  15.  
  16. ------------->8------------------  CUT HERE ----------------------------8<--
  17.  
  18. #include <stdio.h>
  19. #include <time.h>
  20.  
  21. #include <sybfront.h>
  22. #include <sybdb.h>
  23. #include <syberror.h>
  24.  
  25. /* This is the main flaw, since you need to write your login or password in
  26.    the C program. But you have the advantage of just needing to leave a
  27.    compiled version on your server
  28. */
  29.  
  30. #define    DATABASE    "database_name"
  31. #define    LOGIN_NAME    "sa"
  32. #define    PASSWORD    "sa_password"
  33. #define    APP_NAME    "dump"
  34.  
  35. void
  36. main(argc,argv)
  37.         unsigned int    argc;
  38.     char            **argv;
  39. {
  40.     long    t;
  41.     struct tm     *period;
  42.     DBPROCESS       *dbproc;
  43.     LOGINREC        *login;
  44.  
  45.     time(&t);
  46.     period = (struct tm *)localtime(&t);
  47.  
  48.     /* INITIALIZE SYBASE    */
  49.     if (dbinit() == NULL) {
  50.         printf("Error opening the DB\n");
  51.         exit(ERREXIT);
  52.     }
  53.  
  54.     if ((login = dblogin()) == NULL) {
  55.          (void)printf("dblogin() error, exiting \n");
  56.          exit(1);
  57.     }
  58.     DBSETLUSER(login,LOGIN_NAME);
  59.     DBSETLPWD(login, PASSWORD);
  60.     DBSETLAPP(login, APP_NAME);
  61.  
  62.     if ((dbproc = dbopen(login,NULL)) == NULL) {
  63.         (void)printf("dbopen() error, exiting \n");
  64.         exit(1);
  65.     }
  66.  
  67.     /* show time at which dump started        */
  68.     (void)printf("DUMPING DATABASE at %.2d:%.2d ...\n",period->tm_hour,
  69.         period->tm_min);
  70.  
  71.     dbfcmd(dbproc,"dump database %s to tapedump",DATABASE);
  72.     dbsqlexec(dbproc);
  73.     while (dbresults(dbproc) != NO_MORE_RESULTS);
  74.  
  75.     if ((period->tm_wday == 1) || (period->tm_wday == 4)){
  76.         (void)printf("DUMPING TRANSACTION ...\n");
  77.         dbfcmd(dbproc,"dump transaction %s to tapedump\n",DATABASE);
  78.         dbcmd(dbproc,"with truncate_only");
  79.         dbsqlexec(dbproc);
  80.         while (dbresults(dbproc) != NO_MORE_RESULTS);
  81.     }
  82.  
  83.     /* show time at which dump finished        */
  84.     time(&t);
  85.     period = (struct tm *)localtime(&t);
  86.     (void)printf("FINISHED DUMPING DATABASE at %.2d:%.2d ...\n",
  87.         period->tm_hour,period->tm_min);
  88.     dbexit();
  89.     exit(0);
  90. }
  91. ------------->8------------------  CUT HERE ----------------------------8<--
  92.  
  93. Cheers,
  94. -- 
  95. ----8<--------------------------------------------------------------->8------
  96. Tsiel:ohayon@jcpl.co.jp       | If you do not recieve this E-mail, please let me
  97. Employer may not have same | know as soon as possible, if possible.
  98. opinions, if any !         | Two percent of zero is almost nothing.
  99.