Question

Is this approach correct to find out the decimal mark used by SQLite?

#!/usr/bin/env perl
use warnings;
use strict;
use POSIX qw(locale_h);

my $locale_values = localeconv();

my $dec_mark_sqlite = $locale_values->{decimal_point};
Was it helpful?

Solution

You do not need to write any code for this; in the SQL language, . is always the decimal separator, and , always separates list entries.

Please note that when your code interacts with a database, the most direct and efficient way to use floating-point numbers does not require text conversion:

my $sth = $dbh->prepare("SELECT OutVal FROM Tab WHERE InVal > ?");
my $input_value = 1.234;
$sth->execute($input_value);                # no text conversion
while (my $row = $sth->fetchrow_array()) {
    my $output_value = $row[0];             # no text conversion
}

If you are converting floating-point values from/to text, you are likely to do something wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top