Bug Summary

File:libsynthesis/src/sysync_SDK/Sources/admindata.cpp
Warning:line 85, column 3
Value stored to 'err' is never read

Annotated Source Code

1/*
2 * File: admindata.cpp
3 *
4 * Author: Beat Forster (bfo@synthesis.ch)
5 *
6 *
7 * DBApi database adapter
8 * Admin data handling
9 *
10 * Copyright (c) 2005-2011 by Synthesis AG + plan44.ch
11 *
12 * E X A M P L E C O D E
13 * (text_db interface)
14 *
15 */
16
17
18#include "admindata.h"
19#include "SDK_util.h" // include SDK utilities
20#include "SDK_support.h"
21
22
23namespace sysync { // the TAdminData class is part of sysync namespace
24
25#define P_Admin"ADM_" "ADM_" // admin table
26#define P_Map"MAP_" "MAP_" // map table
27
28
29// ---------------------------------------------------------------------------
30void TAdminData::Init( void* aCB, cAppCharP aDBName, string aMapPath,
31 string aContextName,
32 string sDevKey,
33 string sUsrKey )
34{
35 fCB = aCB; // the callback for debug purposes
36 fDBName = aDBName; // DBName, used for debug purposes
37 myDB = fDBName.c_str(); // access the same way as in the textdb module
38
39 fMapPath = aMapPath;
40 fContextName= aContextName;
41 fDevKey = sDevKey;
42 fUsrKey = sUsrKey;
43} // Init
44
45
46/*! Reset the map counter for 'ReadNextMapItem' */
47void TAdminData::ResetMapCounter() {
48 fMap= &fMapList;
49} // ResetMapCounter
50
51
52// Get <mID.flags> string
53string TAdminData::MapID_Flag_Str( cMapID mID, bool asHex )
54{
55 if (asHex) return HexStr( mID->flags );
56 else return IntStr( mID->flags ); // default is integer
57} // MapID_Flag_Str
58
59
60// Get <mID.localID>,<mID.remoteID> <mID.flags> string
61string TAdminData::MapID_Str( cMapID mID )
62{
63 string id= mID->localID;
64 if (*mID->remoteID!=0) { id+= ","; id+= mID->remoteID; } // if
65
66 id+= " flags=" + MapID_Flag_Str( mID, true );
67 id+= " ident=" + IntStr ( (sInt32)mID->ident );
68 return id;
69} // MapID_Str
70
71
72
73// ---------------------------------------------------------------------------
74TSyError TAdminData::LoadAdminData( string aLocDB, string aRemDB, appCharP *adminData )
75{
76 TSyError err;
77 TDBItem* actI;
78
79 string combi = ConcatNames( fUsrKey, fContextName, "_" );
80 combi = ConcatNames( fDevKey, combi, "_" );
81 string admName= ConcatPaths( fMapPath, P_Admin"ADM_" + combi + ".txt" );
82 string mapName= ConcatPaths( fMapPath, P_Map"MAP_" + combi + ".txt" );
83
84 fAdmList.fFileName= admName;
85 err= fAdmList.LoadDB( true, "ADM", fCB );
Value stored to 'err' is never read
86
87 // Get all the elements of the list as a \n separated string <s>
88 string s= ""; actI= &fAdmList;
89 bool found= ListNext( actI );
90 if (found) {
91 TDBItemField* actK= &fAdmList.item; // the key identifier
92 TDBItemField* actF= &actI->item; // the item current field
93 while (ListNext( actK,actF )) {
94 cAppCharP k= actK->field.c_str();
95 cAppCharP f= actF->field.c_str();
96
97 s+= KeyAndField( k,f ) + '\n';
98 } // while
99 }
100 else { // no such element: create a new one with empty admin data
101 string newItemID;
102 fAdmList.CreateEmptyItem( newItemID, actI );
103 DEBUG_DB( fCB, myDB, Da_LA"LoadAdminData", "newItemID='%s'", newItemID.c_str() );
104 } // if
105
106 *adminData= StrAlloc( s.c_str() );
107 fAdm= actI;
108 fAdmList.Disp_Items( fCB );
109 fMapList.fFileName= mapName;
110
111 if (!mapName.empty()) {
112 err= fMapList.LoadDB( false, "", fCB );
113 DEBUG_DB( fCB, myDB, Da_LA"LoadAdminData", "mapFile='%s' err=%d", fMapList.fFileName.c_str(), err );
114 } // if
115
116 ResetMapCounter(); // <aLocDB> and <aRemDB> are not yes use in this implementation
117 DEBUG_DB( fCB, myDB, Da_LA"LoadAdminData", "'%s' '%s'", aLocDB.c_str(),aRemDB.c_str() );
118
119 if (found) return LOCERR_OK;
120 else return DB_NotFound;
121} /* LoadAdminData */
122
123
124TSyError TAdminData::SaveAdminData( cAppCharP adminData )
125{
126 fAdmList.UpdateFields( fCB, adminData, fAdm, true );
127 fAdmList.Disp_Items ( fCB,Da_SA"SaveAdminData" );
128 TSyError err= fAdmList.SaveDB( true, fCB );
129 if (!err)
130 err= fMapList.SaveDB( false,fCB );
131 return err;
132} /* SaveAdminData */
133
134
135
136// ---------------------------------------------------------------------------
137bool TAdminData::ReadNextMapItem( MapID mID, bool aFirst )
138{
139 if (aFirst) ResetMapCounter();
140 string s= "(EOF)";
141 bool ok= ListNext( fMap );
142 if ( ok ) {
143 TDBItem* mpL= &fMapList;
144 TDBItem* act= fMap;
145 mID->localID = StrAlloc( act->itemID.c_str() );
146 mpL->Field( "0",act, s ); mID->remoteID= StrAlloc( s.c_str() );
147 mpL->Field( "1",act, s ); mID->flags = atoi ( s.c_str() );
148 mpL->Field( "2",act, s ); mID->ident = atoi ( s.c_str() );
149 s= MapID_Str( mID );
150 } // if
151
152 DEBUG_DB( fCB, myDB,Da_RM"ReadNextMapItem", "%s", s.c_str() );
153 return ok;
154} // ReadNextMapItem
155
156
157
158TSyError TAdminData::GetMapItem( cMapID mID, TDBItem* &act )
159{
160 TDBItem* mpL= &fMapList;
161 return mpL->GetItem_2( mID->localID, IntStr( (sInt32)mID->ident ).c_str(), mpL, act );
162} // GetMapItem
163
164
165TSyError TAdminData::UpdMapItem( cMapID mID, TDBItem* act )
166{
167 TSyError err= fMapList.UpdateField( fCB, "0", mID->remoteID, act, false );
168 if (!err) err= fMapList.UpdateField( fCB, "1", MapID_Flag_Str( mID ).c_str(), act, false );
169 if (!err) err= fMapList.UpdateField( fCB, "2", IntStr( (sInt32)mID->ident ).c_str(), act, false );
170 return err;
171} // UpdMapItem
172
173
174
175TSyError TAdminData::InsertMapItem( cMapID mID )
176{
177 TDBItem* act;
178 TSyError err= GetMapItem( mID, act );
179 if (!err) err= DB_Error; // Element already exists
180 else {
181 ItemID_Struct a; a.item = mID->localID;
182 a.parent= const_cast<char *>(""); // map items are not hierarchical
183
184 string newItemID;
185 err= fMapList.CreateEmptyItem( &a, newItemID, act );
186 if (!err) err= UpdMapItem ( mID, act );
187 } // if
188
189 DEBUG_DB( fCB, myDB,Da_IM"InsertMapItem", "%s err=%d", MapID_Str( mID ).c_str(), err );
190 return err;
191} // InsertMapItem
192
193
194TSyError TAdminData::UpdateMapItem( cMapID mID )
195{
196 TDBItem* act;
197 TSyError err= GetMapItem( mID, act ); // Element does not yet exist ?
198 if (!err) err= UpdMapItem( mID, act );
199
200 DEBUG_DB( fCB, myDB,Da_UM"UpdateMapItem", "%s err=%d", MapID_Str( mID ).c_str(), err );
201 return err;
202} // UpdateMapItem
203
204
205TSyError TAdminData::DeleteMapItem( cMapID mID )
206{
207 TDBItem* act;
208 TSyError err= GetMapItem( mID, act );
209 if (!err) err= fMapList.DeleteItem( act );
210
211 DEBUG_DB( fCB, myDB,Da_DM"DeleteMapItem", "%s err=%d", MapID_Str( mID ).c_str(), err );
212 return err;
213} // DeleteMapItem
214
215
216} /* namespace */
217/* eof */