Skip to content

Commit

Permalink
Lowercase datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
charsbar committed Feb 26, 2022
1 parent 2d595f3 commit abc241d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion dbdimp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,21 @@ sqlite_db_load_extension(pTHX_ SV *dbh, const char *file, const char *proc)

#endif

SV* _lc(SV* sv) {
int i, l;
char* pv;
if (SvPOK(sv)) {
pv = SvPV_nolen(sv);
l = strlen(pv);
for(i = 0; i < l; i++) {
if (pv[i] >= 'A' && pv[i] <= 'Z') {
pv[i] = pv[i] - 'A' + 'a';
}
}
}
return sv;
}

HV*
sqlite_db_table_column_metadata(pTHX_ SV *dbh, SV *dbname, SV *tablename, SV *columnname)
{
Expand Down Expand Up @@ -1964,7 +1979,7 @@ sqlite_db_table_column_metadata(pTHX_ SV *dbh, SV *dbname, SV *tablename, SV *co
#endif

if (rc == SQLITE_OK) {
hv_stores(metadata, "data_type", datatype ? newSVpv(datatype, 0) : newSV(0));
hv_stores(metadata, "data_type", datatype ? _lc(newSVpv(datatype, 0)) : newSV(0));
hv_stores(metadata, "collation_name", collseq ? newSVpv(collseq, 0) : newSV(0));
hv_stores(metadata, "not_null", newSViv(notnull));
hv_stores(metadata, "primary", newSViv(primary));
Expand Down
2 changes: 1 addition & 1 deletion t/51_table_column_metadata.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for my $call_func (@CALL_FUNCS) {
my $data = $dbh->$call_func(undef, 'foo', 'id', 'table_column_metadata');
ok $data && ref $data eq ref {}, "got a metadata";
ok $data->{auto_increment}, "id is auto incremental";
is lc($data->{data_type}) => 'integer', "data type is correct";
is $data->{data_type} => 'integer', "data type is correct";
ok $data->{primary}, "id is a primary key";
ok !$data->{not_null}, "id is not null";
}
Expand Down

0 comments on commit abc241d

Please sign in to comment.