Re: [sqlite] unique id for table

2013-06-23 Thread e-mail mgbg25171
Yes thanks for the advice...I've already combined the "raw" data i.e.
vectors straight out of the annual reports and the calculated vectors e.g..
"noplat" derived from it which I've given a type "calcd" in the type field
of the same table "itms".
There is some market wide data however, which might not fit into this
vector table Even though the individual items are stored as individual
records.I'm just at the stage of integrating SQLITE with forth and
everything's up for grabs at the moment.



On 23 June 2013 12:42, Simon Slavin  wrote:

>
> On 23 Jun 2013, at 12:26pm, e-mail mgbg25171 
> wrote:
>
> > The "table as a number" idea is necessary to fit my model
> > where word definitions are stored as streams of code pointers (NUMBERS)
> > that just get called.
> > i.e. EVERYTHING has to be a number
>
> That makes perfect sense.
>
> If these tables all have the same fields in you might want to refactor
> your SQLite schema so that these tables are actually all one big table.
>  The thing you currently consider to be a table name would just be a field
> in the big table.
>
> This would give you a single rowid which would indicate both the table and
> the (currently) row in that table.
>
> Simon.
> ___
> 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


Re: [sqlite] unique id for table

2013-06-23 Thread Simon Slavin

On 23 Jun 2013, at 12:26pm, e-mail mgbg25171  wrote:

> The "table as a number" idea is necessary to fit my model
> where word definitions are stored as streams of code pointers (NUMBERS)
> that just get called.
> i.e. EVERYTHING has to be a number

That makes perfect sense.

If these tables all have the same fields in you might want to refactor your 
SQLite schema so that these tables are actually all one big table.  The thing 
you currently consider to be a table name would just be a field in the big 
table.

This would give you a single rowid which would indicate both the table and the 
(currently) row in that table.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] unique id for table

2013-06-23 Thread e-mail mgbg25171
I'm writing a variation of forth (It's got an IDE and 3-level stepping
debugger already)
that's actually a company valuation programming language (Can't get on with
spreadsheets hiding everything)
It accomodates words that are financial report line items (vectors) and
their manipulation
and I'm using SQLITE to store such vectors scraped from pdfs
at various stages i.e. until they fit a standard form allowing comparison
between companies.
The "table as a number" idea is necessary to fit my model
where word definitions are stored as streams of code pointers (NUMBERS)
that just get called.
i.e. EVERYTHING has to be a number
I'm therefore proposing to get at line items and any other piece of
financial info using a number for the table and one for the first row-id
from which you can get the name and type to search for the other values in
the vector.
That's about it and thanks for your interest!







On 23 June 2013 10:06, RSmith  wrote:

> There is of course no straight-forward way to do this, as I've noted Simon
> said already. But my curiosity is very piqued - Mind sharing what kind of
> application requires number-only calling? You using this on a calculator of
> sorts? - If so (or otherwise), some details would be interesting to know.
> (I do some embedded systems, never tried SQLite on it but might, hence the
> interest).
>
> I reply On-list as others might be interested, but will take the
> discussion off-list as it may not really be in the scope of the list (I
> think) if your awaited reply prompts further discussion.
>
> Have a great day!
>
> On 2013/06/22 20:27, e-mail mgbg25171 wrote:
>
>> I need to access a row just using numbers.
>> The row id's fine but can I specify the table using a numeric id too?
>> If not I'll just create a look-up table so there's no problem.
>> I'm just wondering...
>> Any help much appreciated.
>> __**_
>> 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
>
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] unique id for table

2013-06-23 Thread RSmith
There is of course no straight-forward way to do this, as I've noted Simon said already. But my curiosity is very piqued - Mind 
sharing what kind of application requires number-only calling? You using this on a calculator of sorts? - If so (or otherwise), some 
details would be interesting to know. (I do some embedded systems, never tried SQLite on it but might, hence the interest).


I reply On-list as others might be interested, but will take the discussion off-list as it may not really be in the scope of the 
list (I think) if your awaited reply prompts further discussion.


Have a great day!

On 2013/06/22 20:27, e-mail mgbg25171 wrote:

I need to access a row just using numbers.
The row id's fine but can I specify the table using a numeric id too?
If not I'll just create a look-up table so there's no problem.
I'm just wondering...
Any help much appreciated.
___
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


Re: [sqlite] unique id for table

2013-06-22 Thread e-mail mgbg25171
Thanks very much Simon
Looks like plan B then.


On 22 June 2013 19:40, Simon Slavin  wrote:

>
> On 22 Jun 2013, at 7:27pm, e-mail mgbg25171 
> wrote:
>
> > I need to access a row just using numbers.
> > The row id's fine but can I specify the table using a numeric id too?
>
> This command can be used to get tables numbered:
>
> SELECT rowid,name FROM sqlite_master WHERE type='table'
>
> However, if you have tables A, B and C and delete one of them, the numbers
> for other tables can change.  Even creating or deleting indexes can change
> rowids.  So it’s valid only until your schema changes in some way.
>
> Simon.
> ___
> 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


Re: [sqlite] unique id for table

2013-06-22 Thread Simon Slavin

On 22 Jun 2013, at 7:27pm, e-mail mgbg25171  wrote:

> I need to access a row just using numbers.
> The row id's fine but can I specify the table using a numeric id too?

This command can be used to get tables numbered:

SELECT rowid,name FROM sqlite_master WHERE type='table'

However, if you have tables A, B and C and delete one of them, the numbers for 
other tables can change.  Even creating or deleting indexes can change rowids.  
So it’s valid only until your schema changes in some way.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] unique id for table

2013-06-22 Thread e-mail mgbg25171
I need to access a row just using numbers.
The row id's fine but can I specify the table using a numeric id too?
If not I'll just create a look-up table so there's no problem.
I'm just wondering...
Any help much appreciated.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-28 Thread Simon Slavin

On 28 Oct 2011, at 8:20am, Tamara Cattivelli wrote:

> how can I let the database generate a generally unique id(guid, String)?

The database will generate a unique integer for the row itself whenever you 
save a row without specifying the id.  You can insert a row then tell what 
integer it used using the C function 'sqlite3_last_insert_rowid()'



or the SQLite function 'last_insert_rowid()'



SQLite has no understanding of GUIDs.  By all means, generate one yourself and 
use it in a SQLite database, but SQLite won't generate one for you.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-28 Thread Tamara Cattivelli
Hi,
how can I let the database generate a generally unique id(guid, String)?
Thanks, Tamara

2011/10/27, Simon Slavin :
>
> On 27 Oct 2011, at 10:04pm, Kees Nuyt wrote:
>
>> On Thu, 27 Oct 2011 21:47:17 +0100, Simon Slavin
>>  wrote:
>>
>>> On 27 Oct 2011, at 8:12pm, Tim Streater wrote:
>>>
 Is there a way to get a unique id from a database
 without actually creating a new row?
>>>
>>> Sure.  Do something like
>>>
>>> SELECT max(id) FROM mytab;
>>>
>>> Then in your own code, add 1 to it and use that as
>>> the "id" for the row you're about to save.
>>> Make sure you handle the NULL case (where mytab
>>> doesn't have any rows in it yet) correctly.
>>
>> And wrap it all in an IMMEDIATE or EXCLUSIVE transaction, or
>> you'll get a race condition if some other process tries to do the
>> same at the same time.
>
> Oh right.  Yes, if you have more than one process doing this at the same
> time, you're screwed.  Better just to pick a random integer out of a huge
> range and use that.
>
> Simon.
> ___
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>

-- 
Gesendet von meinem Mobilgerät
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-27 Thread Tim Streater
On 27 Oct 2011 at 22:04, Kees Nuyt  wrote: 

> On Thu, 27 Oct 2011 21:47:17 +0100, Simon Slavin
>  wrote:
>
>>
>> On 27 Oct 2011, at 8:12pm, Tim Streater wrote:
>>
>>> Is there a way to get a unique id from a database
>>> without actually creating a new row?
>>
>> Sure.  Do something like
>>
>> SELECT max(id) FROM mytab;
>>
>> Then in your own code, add 1 to it and use that as
>> the "id" for the row you're about to save.
>> Make sure you handle the NULL case (where mytab
>> doesn't have any rows in it yet) correctly.
>
> And wrap it all in an IMMEDIATE or EXCLUSIVE transaction, or
> you'll get a race condition if some other process tries to do the
> same at the same time.
> All processes have to behave, if there's one that does the SELECT
> above in uncommitted mode and proceeds to use it, you have a
> problem.
> So, better use AUTOINCREMENT.

Thanks for the various responses. I hadn't thought of the max(id) approach but 
I'm not sure I can put a BEGIN/COMMIT around everything, as there are network 
exchanges involved there too. Nothing at the SQLite web site gave me a better 
clue than my own approach, either, but it doesn't look like there's anything 
obvious I overlooked.

--
Cheers  --  Tim
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-27 Thread Simon Slavin

On 27 Oct 2011, at 10:04pm, Kees Nuyt wrote:

> On Thu, 27 Oct 2011 21:47:17 +0100, Simon Slavin
>  wrote:
> 
>> On 27 Oct 2011, at 8:12pm, Tim Streater wrote:
>> 
>>> Is there a way to get a unique id from a database
>>> without actually creating a new row?
>> 
>> Sure.  Do something like
>> 
>> SELECT max(id) FROM mytab;
>> 
>> Then in your own code, add 1 to it and use that as
>> the "id" for the row you're about to save. 
>> Make sure you handle the NULL case (where mytab
>> doesn't have any rows in it yet) correctly.
> 
> And wrap it all in an IMMEDIATE or EXCLUSIVE transaction, or
> you'll get a race condition if some other process tries to do the
> same at the same time. 

Oh right.  Yes, if you have more than one process doing this at the same time, 
you're screwed.  Better just to pick a random integer out of a huge range and 
use that.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-27 Thread Kees Nuyt
On Thu, 27 Oct 2011 21:47:17 +0100, Simon Slavin
 wrote:

>
>On 27 Oct 2011, at 8:12pm, Tim Streater wrote:
>
>> Is there a way to get a unique id from a database
>> without actually creating a new row?
>
> Sure.  Do something like
>
> SELECT max(id) FROM mytab;
>
> Then in your own code, add 1 to it and use that as
> the "id" for the row you're about to save. 
> Make sure you handle the NULL case (where mytab
> doesn't have any rows in it yet) correctly.

And wrap it all in an IMMEDIATE or EXCLUSIVE transaction, or
you'll get a race condition if some other process tries to do the
same at the same time. 
All processes have to behave, if there's one that does the SELECT
above in uncommitted mode and proceeds to use it, you have a
problem.
So, better use AUTOINCREMENT.

-- 
  (  Kees Nuyt
  )
c[_]
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-27 Thread Simon Slavin

On 27 Oct 2011, at 8:12pm, Tim Streater wrote:

> Is there a way to get a unique id from a database without actually creating a 
> new row?

Sure.  Do something like

SELECT max(id) FROM mytab;

Then in your own code, add 1 to it and use that as the "id" for the row you're 
about to save.  Make sure you handle the NULL case (where mytab doesn't have 
any rows in it yet) correctly.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-27 Thread Kit
2011/10/27 Tim Streater :
> Is there a way to get a unique id from a database without actually creating a 
> new row? If I have:
> Cheers  --  Tim

sqlite> CREATE TABLE test (id integer primary key autoincrement, name text);
sqlite> INSERT INTO test (name) VALUES ('xx');
sqlite> BEGIN;
sqlite> UPDATE sqlite_sequence SET seq=seq+3 WHERE name='test';
sqlite> SELECT seq FROM sqlite_sequence WHERE name='test';
4
sqlite> END;
sqlite> INSERT INTO pokus (name) VALUES ('xxx');
sqlite> SELECT * FROM test;
1|xx
5|xxx
-- 
Kit
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Unique id

2011-10-27 Thread Pavel Ivanov
What's wrong with the following (pseudo-code)?

begin immediate
x = result of (select max(j) from mytab;);
++x;
for  (n=0;  n wrote:
> Is there a way to get a unique id from a database without actually creating a 
> new row? If I have:
>
> create table mytab (i integer primary key, j);
>
> then I could do (pseudo-code):
>
> insert into mytab (i) values (null);
> x = result of (select last_insert_rowid() from mytab;);
>
> for  (n=0;  n     {
>     insert into mytab (j) values (x);
>     }
>
> delete from mytab where i=x;
>
>
> This would give me my desired result of having a set of rows with the same 
> j-value (other columns differ, of course). The insert in the for-loop is 
> actually done elsewhere so it doing as above simplifies the logic. As num may 
> be zero I may not in fact need the unique value. What I'd like would be a way 
> of asking table mytab for a unique value that may or may not get used, but 
> without the need to thereby create a row that I later have to delete.
>
> --
> Cheers  --  Tim
>
> ___
> 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


[sqlite] Unique id

2011-10-27 Thread Tim Streater
Is there a way to get a unique id from a database without actually creating a 
new row? If I have:

create table mytab (i integer primary key, j);

then I could do (pseudo-code):

insert into mytab (i) values (null);
x = result of (select last_insert_rowid() from mytab;);

for  (n=0;  n

Re: [sqlite] unique id maximum value limiting

2007-09-03 Thread Babu, Lokesh
#ifdef SQLITE_INT64_TYPE
  typedef SQLITE_INT64_TYPE sqlite_int64;
  typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
#elif defined(_MSC_VER) || defined(__BORLANDC__)
  typedef __int64 sqlite_int64;
  typedef unsigned __int64 sqlite_uint64;
#else
  typedef long long sqlite_int64;
  typedef unsigned long long int sqlite_uint64;
#endif

Try changing the above statements in your sqlite3.h,
typedef int sqlite_int64;
typedef unsigned int sqlite_uint64, as appropriate for you.

Anybody please correct me if I'm wrong.


On 9/3/07, Sreedhar.a <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am working on a 16 bit processor.
> In windows the maximum value of unique id is 2 power 63 -1
>
> I want to restrict the maximum value of the unique id to 2 power 15 -1
>
> Can anyone help me in this?.
>
> Best Regards,
> A.Sreedhar.
>
> Jasmin Infotech Pvt. Ltd.
> Plot 119, Velachery Tambaram Road,
> (Opposite NIOT), Pallikaranai,
> Chennai 601 302
> India
> Tel: +91 44 3061 9600 ext 3057
> Fax: + 91 44 3061 9605
>
>
> ***
> Information in this email is proprietary and Confidential to
> Jasmin Infotech. Any use, copying or dissemination of the
> information in any manner is strictly prohibited. If you are
> not the intended recipient, please destroy the message and please inform us.
>
> 
>
>

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] unique id maximum value limiting

2007-09-03 Thread Sreedhar.a
Hi,
 
I am working on a 16 bit processor.
In windows the maximum value of unique id is 2 power 63 -1 
 
I want to restrict the maximum value of the unique id to 2 power 15 -1
 
Can anyone help me in this?.
 
Best Regards,
A.Sreedhar.
 
Jasmin Infotech Pvt. Ltd.
Plot 119, Velachery Tambaram Road,
(Opposite NIOT), Pallikaranai,
Chennai 601 302
India
Tel: +91 44 3061 9600 ext 3057
Fax: + 91 44 3061 9605 
 

***
Information in this email is proprietary and Confidential to 
Jasmin Infotech. Any use, copying or dissemination of the
information in any manner is strictly prohibited. If you are 
not the intended recipient, please destroy the message and please inform us.