diff --git a/lazarus/DBConnection.pas b/lazarus/DBConnection.pas index c64831a..b09f14e 100644 --- a/lazarus/DBConnection.pas +++ b/lazarus/DBConnection.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, sqlite3conn, sqldb, DB, FileUtil, Forms, Controls, - Graphics, Dialogs, DBGrids, book, booktype, rental, student; + Graphics, Dialogs, DBGrids, book, booktype, rental, student, DBConstants; type ArrayOfStudents = array of TStudent; @@ -423,7 +423,7 @@ function TDBConnection.updateInsertStudent(student: TStudent): boolean; FieldByName('first_name').AsString := student.getFirstName; FieldByName('class_name').AsString := student.getClassName; - if student.getBirth <= -1 then //if set to null + if student.getBirth = SQLNull then //if set to null FieldByName('birth').Clear else FieldByName('birth').AsDateTime := student.getBirth; @@ -590,7 +590,7 @@ function TDBConnection.updateInsertRental(rental: TRental): boolean; FieldByName('book_id').AsLargeInt := rental.getBookId; FieldByName('rental_date').AsDateTime := rental.getRentalDate; - if rental.getReturnDate <= -1 then //if set to null + if rental.getReturnDate = SQLNull then //if set to null FieldByName('return_date').Clear else FieldByName('return_date').AsDateTime := rental.getReturnDate; diff --git a/lazarus/dbconstants.pas b/lazarus/dbconstants.pas new file mode 100644 index 0000000..7bbe344 --- /dev/null +++ b/lazarus/dbconstants.pas @@ -0,0 +1,12 @@ +unit DBConstants; + +{$mode objfpc}{$H+} + +interface + +const + SQLNull = -1; + +implementation + +end. diff --git a/lazarus/rental.pas b/lazarus/rental.pas index aa4f1b5..02d0c4a 100644 --- a/lazarus/rental.pas +++ b/lazarus/rental.pas @@ -5,7 +5,7 @@ interface uses - Classes, SysUtils; + Classes, SysUtils, DBConstants; type TRental = class @@ -146,8 +146,8 @@ constructor TRental.Create; self.id := -1; self.book_id := -1; self.student_id := -1; - self.return_date := -1; // -1 or smaller equals NULL - self.rental_date := -1; + self.return_date := SQLNull; + self.rental_date := SQLNull; end; end. diff --git a/lazarus/student.pas b/lazarus/student.pas index bf0f697..c5a3443 100644 --- a/lazarus/student.pas +++ b/lazarus/student.pas @@ -5,7 +5,7 @@ interface uses - Classes, SysUtils; + Classes, SysUtils, DBConstants; type TStudent = class @@ -172,7 +172,7 @@ constructor TStudent.Create; self.last_name := ''; self.first_name := ''; self.class_name := ''; - self.birth := -1; // -1 or smaller equals NULL + self.birth := SQLNull; self.ldap_user := ''; end;