Interesting idea. Thanks.

Adam

On Tue, Aug 7, 2012 at 12:07 PM, Black, Michael (IS)
<michael.bla...@ngc.com> wrote:
> You can use sscanf to determine data type...I've done it before using a 
> method that's not obvious...
>
> You parse from most restrictive to least restrictive format like this...this 
> will accept any valid float format including scientific notation.
>
> #include <stdio.h>
>
> enum {UNKNOWN, FLOAT, INT, STRING};
>
> int datatype(char *s)
> {
>   long i;
>   double f;
>   char buf[4096];
>   int n;
>   n = sscanf(s,"%d%s",&i,buf);
>   if (n == 1) {
>     printf("INT\n");
>     return INT;
>   }
>   n = sscanf(s,"%lg%s",&f,buf);
>   if (n == 1) {
>     printf("FLOAT\n");
>     return FLOAT;
>   }
>   n = sscanf(s,"%s",buf);
>   if (n == 1) {
>     printf("STRING\n");
>     return STRING;
>   }
>   else {
>      printf("UNKNOWN\n");
>     return UNKNOWN; // should never get here
>   }
> }
>
> main()
> {
>   char *line1="1234";
>   char *line2="1234.5";
>   char *line3="x1234.5";
>   datatype(line1);
>   datatype(line2);
>   datatype(line3);
> }
> ~
>
> Michael D. Black
> Senior Scientist
> Advanced Analytics Directorate
> Advanced GEOINT Solutions Operating Unit
> Northrop Grumman Information Systems
>
> ________________________________________
> From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
> behalf of Adam DeVita [adev...@verifeye.com]
> Sent: Tuesday, August 07, 2012 10:26 AM
> To: General Discussion of SQLite Database
> Subject: EXT :[sqlite] C# Dynamic data type
>
> Good day,
>
> I've been reading a bit of conflicted stuff online in terms of data type.
>
> The most basic question, in  C#, is can you easily determine the data
> type of the Nth entry in a column.
>
> {Ex: Create table A( x TEXT, y )
>  ... a few  inserts, binding a float, then a string, then an int into y..
>
>  select x,y from A
> check the type of y before retrieving a value from it.
> }
>
>
> The docs for  SQLiteDataReader.GetFieldType() seems to read as if it
> will return the column affinity.
>
> regards,
> Adam
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



-- 
VerifEye Technologies Inc.
905-948-0015x245
151 Whitehall Dr, Unit 2
Markham ON, L3R 9T1
Canada
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to