Changeset 297 for trunk/includes/dbc.php
- Timestamp:
- Dec 28, 2009, 2:32:52 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/dbc.php
r234 r297 38 38 $this->GenerateOffsetTable($Format); 39 39 if($this->Offsets[count($this->Offsets) - 1] != $this->RecordSize) 40 40 die(RECORD_SIZE_NOT_MATCH.$this->Offsets[count($this->Offsets) - 1].' <> '.$this->RecordSize); 41 41 } 42 42 … … 47 47 $this->WriteUint(0x43424457); 48 48 49 50 49 $this->StringList = array(); 50 $this->StringOffset = 1; 51 51 $this->Format = $Format; 52 52 $this->GenerateOffsetTable($Format); 53 54 55 56 53 $this->FieldCount = strlen($Format); 54 $this->RecordCount = 0; 55 $this->RecordSize = $this->Offsets[count($this->Offsets) - 1]; 56 $this->StringBlockSize = 0; 57 57 58 58 $this->WriteUint($this->RecordCount); … … 65 65 { 66 66 $this->Offsets = array(); 67 67 $this->Offsets[0] = 0; 68 68 for($I = 0; $I < strlen($Format); $I++) 69 69 { … … 72 72 { 73 73 case "b": 74 75 $this->Offsets[$I + 1] += 1; 76 74 case "X": 75 $this->Offsets[$I + 1] += 1; 76 break; 77 77 case "x": 78 79 80 81 82 $this->Offsets[$I + 1] += 4; 83 78 case "u": 79 case "i": 80 case "f": 81 case "s": 82 $this->Offsets[$I + 1] += 4; 83 break; 84 84 } 85 85 } … … 142 142 public function GetString($Row, $Column) 143 143 { 144 144 $Offset = $this->GetUint($Row, $Column); 145 145 146 146 $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset; 147 147 if($Position >= $this->GetSize()) return(''); 148 148 $this->Seek($Position); 149 149 … … 158 158 public function SetString($Row, $Column, $Value) 159 159 { 160 161 162 163 164 165 166 167 168 169 160 if(in_array($Value, $this->StringList)) 161 { 162 $this->SetUint($Row, $Column, $this->StringListOffset[array_search($Value, $this->StringList)]); 163 } else 164 { 165 $this->SetUint($Row, $Column, $this->StringOffset); 166 $this->StringList[] = $Value; 167 $this->StringListOffset[] = $this->StringOffset; 168 $this->StringOffset += strlen($Value) + 1; 169 } 170 170 } 171 171 172 172 public function Commit() 173 173 { 174 174 $this->Seek(0); 175 175 $this->WriteUint(0x43424457); 176 176 $this->WriteUint($this->RecordCount); … … 178 178 $this->WriteUint($this->RecordSize); 179 179 $this->WriteUint($this->StringOffset); 180 181 182 183 { 180 $this->Seek($this->HeaderSize + $this->RecordCount * $this->RecordSize); 181 $this->WriteByte(0); 182 foreach($this->StringList as $Index => $Item) 183 { 184 184 $this->WriteString($Item); 185 185 } 186 186 } 187 187 … … 194 194 { 195 195 case 'b': 196 197 196 $Line[$I] = $this->GetByte($Row, $I); 197 break; 198 198 case 'u': 199 200 199 $Line[$I] = $this->GetUint($Row, $I); 200 break; 201 201 case 'i': 202 203 202 $Line[$I] = $this->GetInt($Row, $I); 203 break; 204 204 case 'f': 205 206 205 $Line[$i] = $this->GetFloat($Row, $I); 206 break; 207 207 case 's': 208 209 208 $Line[$I] = $this->GetString($Row, $I); 209 break; 210 210 case 'x': 211 212 213 211 case 'X': 212 default: 213 break; 214 214 } 215 215 } … … 224 224 { 225 225 case 'b': 226 227 226 $this->SetByte($Row, $I, $Line[$I]); 227 break; 228 228 case 'u': 229 230 229 $this->SetUint($Row, $I, $Line[$I]); 230 break; 231 231 case 'i': 232 233 232 $this->SetInt($Row, $I, $Line[$I]); 233 break; 234 234 case 'f': 235 236 235 $this->SetFloat($Row, $I, $Line[$i]); 236 break; 237 237 case 's': 238 239 238 $this->SetString($Row, $I, $Line[$I]); 239 break; 240 240 case 'x': 241 242 243 241 case 'X': 242 default: 243 break; 244 244 } 245 245 } … … 255 255 { 256 256 case 'b': 257 258 257 $Line[$I] = $this->GetByte($Row, $Columns[$I]); 258 break; 259 259 case 'u': 260 261 260 $Line[$I] = $this->GetUint($Row, $Columns[$I]); 261 break; 262 262 case 'i': 263 264 263 $Line[$I] = $this->GetInt($Row, $Columns[$I]); 264 break; 265 265 case 'f': 266 267 266 $Line[$i] = $this->GetFloat($Row, $Columns[$I]); 267 break; 268 268 case 's': 269 270 269 $Line[$I] = $this->GetString($Row, $Columns[$I]); 270 break; 271 271 case 'x': 272 273 274 272 case 'X': 273 default: 274 break; 275 275 } 276 276 } … … 280 280 public function GetRecordCount() 281 281 { 282 282 return($this->RecordCount); 283 283 } 284 284 285 285 public function SetRecordCount($Value) 286 286 { 287 287 $this->RecordCount = $Value; 288 288 } 289 289 290 290 public function GetFieldCount() 291 291 { 292 292 return($this->FieldCount); 293 293 } 294 294 }
Note:
See TracChangeset
for help on using the changeset viewer.