TclMySQL.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.1 $
00022 // $Date: 2005/07/25 18:06:09 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/database/TclMySQL.cpp,v $
00024                                                                         
00025 // Written: fmk
00026 
00027 // Description: This file contains the function invoked when the user invokes
00028 // the MySQL command in the interpreter. 
00029 //
00030 // What: "@(#) TclCommand_MySQL.C, revA"
00031 
00032 #include <OPS_Globals.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <tcl.h>
00036 
00037 #include <MySqlDatastore.h>
00038 
00039 #ifdef _USRDLL
00040 #define DllExport _declspec(dllexport)
00041 #else
00042 #define DllExport
00043 #endif
00044 
00045 extern "C" DllExport int
00046 TclCommand_MySQL(ClientData clientData, 
00047                  Tcl_Interp *interp,  
00048                  int argc, 
00049                  TCL_Char **argv, 
00050                  Domain *theDomain, 
00051                  FEM_ObjectBroker *theBroker,
00052                  FE_Datastore **theDatabase)
00053 {
00054   
00055   if (argc < 3) {
00056     opserr << "WARNING database MySql dabaseName? ";
00057     return TCL_ERROR;
00058   }    
00059   
00060   // delete the old database
00061   if (*theDatabase != 0)
00062     delete (*theDatabase);
00063   
00064   if (argc == 3)
00065     (*theDatabase) = new MySqlDatastore(argv[2], *theDomain, *theBroker);
00066   else {
00067     const char *database = argv[2];
00068     const char *host = NULL;
00069     const char *user = NULL;
00070     const char *passwd = NULL;
00071     const char *socket = NULL;
00072     int port = 0;
00073     int clientFlag = 0;
00074     
00075     int counter = 3;
00076     while (counter < argc) {
00077       if (strcmp(argv[counter],"-host") == 0) {
00078         host = argv[counter + 1];
00079         counter += 2;
00080       } else if (strcmp(argv[counter],"-user") == 0) {
00081         user = argv[counter + 1];
00082         counter += 2;
00083       } else if (strcmp(argv[counter],"-passwd") == 0) {
00084         passwd = argv[counter + 1];
00085         counter += 2;
00086       } else if (strcmp(argv[counter],"-socket") == 0) {
00087         socket = argv[counter + 1];
00088         counter += 2;
00089       } else if (strcmp(argv[counter],"-port") == 0) {
00090         if (Tcl_GetInt(interp, argv[counter+1], &port) != TCL_OK)       
00091           return TCL_ERROR;           
00092         counter += 2;
00093       } else if (strcmp(argv[counter],"-clientFlag") == 0) {
00094         if (Tcl_GetInt(interp, argv[counter+1], &clientFlag) != TCL_OK) 
00095           return TCL_ERROR;           
00096         counter += 2;
00097       } else {
00098         counter++;
00099       }
00100     }
00101     (*theDatabase) = new MySqlDatastore(database, host, user, passwd, port, socket, clientFlag, *theDomain, *theBroker);
00102   } 
00103 
00104   if (*theDatabase == 0) {
00105     opserr << "WARNING database MySql dabaseName? - out of memory\n";
00106     return TCL_ERROR;
00107   }
00108   
00109   return TCL_OK;
00110 }
00111 

Generated on Mon Oct 23 15:05:00 2006 for OpenSees by doxygen 1.5.0