first c version
functional implementation using sqlite