summaryrefslogtreecommitdiff
path: root/src/sql/xbset.cpp
blob: 98de3091f6e338d5617417c9cf6797a2a49df53c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* xbset.cpp

XBase64 Software Library

Copyright (c) 1997,2003,2014,2022 Gary A Kunkel

The xb64 software library is covered under the terms of the GPL Version 3, 2007 license.

Email Contact:

    XDB-devel@lists.sourceforge.net
    XDB-users@lists.sourceforge.net

*/

#include "xbase.h"

#ifdef XB_SQL_SUPPORT

namespace xb{


/***********************************************************************/
xbInt16 xbSql::SqlSet( const xbString &sCmdLine ){

  // std::cout << "SET [" << sCmdLine << "]\n";
  // expected format:
  //  SET ATTRIBUTE = DATAVALUE
  //  SET ATTRIBUTE = ^     (to delete an entry)

  xbInt16  iRc = 0;
  xbInt16  iErrorStop = 0;
  xbUInt32 ulPos;

  try{

    xbString sCmd = sCmdLine;
    sCmd.Trim();
    sCmd.ZapTrailingChar( ';' );
    sCmd.Trim();

    // drop off the first node "SET"
    ulPos = sCmd.Pos( ' ' );
    sCmd.Ltrunc( ulPos );
    sCmd.Ltrim();

    xbString sNode1 = sCmd;
    sNode1.ToUpperCase();

    if( sNode1 == "SET" ) {
        uda.DumpUda();

    } else {

      xbString sKey;
      sKey.ExtractElement( sCmd, '=', 1, 0 );
      sKey.Trim();

      xbString sToken;
      sToken.ExtractElement( sCmd, '=', 2, 0 );
      sToken.Trim();


      if( sToken == '^' ){
        if(( iRc = uda.DelTokenForKey( sKey )) != XB_NO_ERROR ){
          iErrorStop = 10;
          throw iRc;
        }
      } else {
        if(( iRc = uda.UpdTokenForKey( sKey, sToken )) != XB_NO_ERROR ){
          iErrorStop = 10;
          throw iRc;
        }
      }
    }

  }
  catch (xbInt16 iRc ){
    xbString sMsg;
    sMsg.Sprintf( "xbSql::SqlSet() Exception Caught. Error Stop = [%d] rc = [%d]", iErrorStop, iRc );
    xbase->WriteLogMessage( sMsg.Str() );
    xbase->WriteLogMessage( GetErrorMessage( iRc ));
  }

  return iRc;
}

/***********************************************************************/
}              /* namespace       */
#endif         /*  XB_SQL_SUPPORT */