Skip to content

Commit

Permalink
addition to 9207b8e
Browse files Browse the repository at this point in the history
  • Loading branch information
cnmicha committed Mar 8, 2017
1 parent 381164f commit 24d7817
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
12 changes: 9 additions & 3 deletions lazarus/DBConnection.pas
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,11 @@ procedure TDBConnection.setBookFields(var resultVar: ArrayOfBooks; returnOne: bo
resultVar[length(resultVar) - 1] := TBook.Create; //create new book object
resultVar[length(resultVar) - 1].setId(FieldByName('id').AsLargeInt);
resultVar[length(resultVar) - 1].setIsbn(FieldByName('isbn').AsString);
resultVar[length(resultVar) - 1].setCondition(
FieldByName('condition').AsInteger);

if not (FieldByName('condition').IsNull) then
resultVar[length(resultVar) - 1].setCondition(
FieldByName('condition').AsInteger);

if returnOne then
exit;
Next;
Expand Down Expand Up @@ -840,7 +843,10 @@ procedure TDBConnection.setBooktypeFields(var resultVar: ArrayOfBookTypes;
resultVar[length(resultVar) - 1].setIsbn(FieldByName('isbn').AsString);
resultVar[length(resultVar) - 1].setTitle(FieldByName('title').AsString);
resultVar[length(resultVar) - 1].setSubject(FieldByName('subject').AsString);
resultVar[length(resultVar) - 1].setStorage(FieldByName('storage').AsInteger);

if not (FieldByName('storage').IsNull) then
resultVar[length(resultVar) - 1].setStorage(FieldByName('storage').AsInteger);

if returnOne then
exit;
Next;
Expand Down
10 changes: 5 additions & 5 deletions lazarus/book.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, SysUtils;
Classes, SysUtils, DBConstants;

type
TBook = class
Expand Down Expand Up @@ -38,7 +38,7 @@ TBook = class

// Sets a new book condition
// parameter: newCondition
// result: TRUE on success, so if newIsbn has 1 character, is <=5 and not NULL
// result: TRUE on success, so if newIsbn has 1 character, is <=5 or is =SQLNull
function setCondition(newCondition: cardinal): boolean;

constructor Create;
Expand Down Expand Up @@ -97,7 +97,7 @@ function TBook.getCondition(): cardinal;
function TBook.setCondition(newCondition: cardinal): boolean;
begin
Result := False;
if (newCondition <= 6) then
if (newCondition = SQLNull ) or (newCondition <= 6) then
begin
self.condition := newCondition;
Result := True;
Expand All @@ -106,9 +106,9 @@ function TBook.setCondition(newCondition: cardinal): boolean;

constructor TBook.Create;
begin
self.id := -1;
self.id := SQLNull;
self.isbn := '';
self.condition := 0;
self.condition := SQLNull;
end;

end.
8 changes: 4 additions & 4 deletions lazarus/booktype.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, SysUtils;
Classes, SysUtils, DBConstants;

type
TBooktype = class
Expand Down Expand Up @@ -48,7 +48,7 @@ TBooktype = class

// Sets a new book storage
// parameter: newStorage
// result: TRUE on success, so if newStorage <= (2^63)-1)
// result: TRUE on success, so if newStorage <= (2^63)-1) or =SQLNull
function setStorage(newStorage: integer): boolean;

constructor Create;
Expand Down Expand Up @@ -119,7 +119,7 @@ function TBooktype.getStorage(): integer;
function TBooktype.setStorage(newStorage: integer): boolean;
begin
Result := False;
if (newStorage <> NULL) then
if (newStorage = SQLNull) or (newStorage <> NULL) then
begin
self.storage := newStorage;
Result := True;
Expand All @@ -131,7 +131,7 @@ constructor TBooktype.Create;
self.isbn := '';
self.title := '';
self.subject := '';
self.storage := 0;
self.storage := SQLNull;
end;

end.
10 changes: 5 additions & 5 deletions lazarus/rental.pas
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TRental = class

// Sets a new book return datetime in seconds
// parameter: newReturnDate
// result: TRUE on success, so if newReturnDate >= 0 and not NULL
// result: TRUE on success, so if newReturnDate >= 0 or =SQLNull
function setReturnDate(newReturnDate: TDate): boolean;

// Returns the book rental datetime in seconds
Expand Down Expand Up @@ -119,7 +119,7 @@ function TRental.getReturnDate(): TDate;
function TRental.setReturnDate(newReturnDate: TDate): boolean;
begin
Result := False;
if (newReturnDate <> NuLL) and (newReturnDate >= 0) then
if (newReturnDate = SQLNull) or (newReturnDate <> NuLL) and (newReturnDate >= 0) then
begin
self.return_date := newReturnDate;
Result := True;
Expand All @@ -143,9 +143,9 @@ function TRental.setRentalDate(newRentalDate: TDate): boolean;

constructor TRental.Create;
begin
self.id := -1;
self.book_id := -1;
self.student_id := -1;
self.id := SQLNull;
self.book_id := SQLNull;
self.student_id := SQLNull;
self.return_date := SQLNull;
self.rental_date := SQLNull;
end;
Expand Down
2 changes: 1 addition & 1 deletion lazarus/student.pas
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function TStudent.setLDAPUser(newLDAPUser: string): boolean;

constructor TStudent.Create;
begin
self.id := -1;
self.id := SQLNull;
self.last_name := '';
self.first_name := '';
self.class_name := '';
Expand Down

0 comments on commit 24d7817

Please sign in to comment.