Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save attendance in database #121

Open
Aminechouchene98 opened this issue Aug 18, 2022 · 2 comments
Open

save attendance in database #121

Aminechouchene98 opened this issue Aug 18, 2022 · 2 comments

Comments

@Aminechouchene98
Copy link

i am trying to save attendance in database but i get this error can someone help me
err1
err2
?

@erkutcin
Copy link

i am trying to save attendance in database but i get this error can someone help me err1 err2 ?

Hi Aminechouchene98, i made all updates. But i am still not able to retrieve the datas. Could you advise me how did you do it? Thanks in advance

@IncubuzzCC
Copy link

Hi erkutcin ,
This likely seems to be a database issue on your end, and not a device issue with the library.

In my case the uid returns the position the user record is stored in the device while id is the actual user id.
In your case it looks like yours is storing a consecutive id in the uid field and the user id in the id field.
Therefore thw data structure may slightly vary across devices.

As long as you do not clear attendance records the device by using the clearAttendance() function, the device will give you the same data plus the new attendance records.
If you clear the attendance records, which you probably should every once in a while to keep the download from becoming slow,

We worked around this by creating a combined primary key (or you could use a unique index) over the user id and the date time field.

CREATE TABLE ``deviceusers` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(75) COLLATE utf8mb4_unicode_ci NOT NULL,
  `synctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `fetched` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
);

CREATE TABLE `deviceregs` (
  `deviceuser_id` smallint(5) unsigned NOT NULL,
  `time` datetime NOT NULL,
  `fetched` tinyint(3) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`deviceuser_id`,`time`),
  CONSTRAINT `deviceregs_deviceuser_id_foreign` FOREIGN KEY (`deviceuser_id`) REFERENCES `deviceusers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
);

This way you could use INSERT IGNORE or capture inserts that fail due to duplication.

I hope this helps.

Sample device attendance:

[23] => Array([0] => 29, [1] => 3, [2] => 0, [3] => 2022-12-09 19:02:00)
[24] => Array([0] => 9, [1] => 9, [2] => 0, [3] => 2022-12-10 07:39:07)
[25] => Array([0] => 163, [1] => 162, [2] => 0, [3] => 2022-12-10 07:41:35)

Sample device users:

[9] => Array([0] => 9, [1] => Josef, [2] => 0, [3] => )
[29] => Array([0] => 3, [1] => Fred, [2] => 14, [3] => 696910)
[163] => Array([0] => 162, [1] => Bernard, [2] => 0, [3] => )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants