00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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