dBase IV Database not indexed - dbase

I'm working with dBase IV, I can't figure why the error Database not indexed occurs after closing the new database created.
reproducing the behavior:
create database
add two fields
close all
use database
seek 1

After lot tries accidentally found the answer, when I open the database I need to set the order with the index
USE FOO
DISPLAY STRUCTURE
Field Field Name Type Width Dec Index
1 ID Numeric 6 Y
2 TEXT Character 60 N
CLOSE ALL
Open setting the order
USE FOO ORDER ID
SEEK <ID_NUMBER>

Related

How do I make multiple insertions into a SQLite DB from UIPath

I have an excel spreadsheet with multiple entries that I want to insert into an SQLite DB from UIPath. How do I do this?
You could do it one of two ways. For both methods, you will need to use the Excel Read Range to put the excel into a table.
Scenario 1: You could read the table in a for each loop, line by line, converting each row to SQL and use a Execute non-query activity. This is too long, and if you like O notation, this is an O(n) solution.
Scenario 2: You could upload the entire table (as long as its compatible with the DB Table) to the database.
you will need Database > Insert activity
You will need to provide the DB Connection (which I answer in another post how to create)
Then enter the sqlite database table you want to insert into in Quotes
And then enter the table name that you have created or pulled from another resource in the last field
Output will be an integer (Affected Records)
For O Notation, this is an O(1) solution. At least from our coding perspective

Get a Value from One Cell in Sqlite to Livecode

I am using sqlite as my database. It is connected to the livecode project.
The Contacts table has the following data (address and contact number are omitted for security)
ID Name Address Contact No.
1 John ...Philippines 0999999999
2 Kim ...Philippines 0999999999
When I executed this command...
SELECT Name from Contacts ORDER BY ID DESC LIMIT 1
It will return
Kim
In Livecode, I want to store that value to the variable and display it as a Message Box.
How to do that?
You can use any of LiveCodes database functions. First you need to open the database via:
revOpenDatabase("sqlite",filepath[,sqliteOptions])
Then you can query the database via one of the query commands:
revQueryDatabase(databaseID,SQLQuery[,{variablesList | arrayName}])
There is also a function called revDataFromQuery([columnDelim],[rowDelim],databaseID,SQLQuery[,varsList]) that you might use for your query.
Look them up in your dictionary and you may also have a look at the "Book Database" provided via the start center.
So using the last function you can use:
put revOpenDatabase("sqlite","/path/to/your/database") into tDB
revDataFromQuery(,,tDB,"SELECT Name from Contacts ORDER BY ID DESC LIMIT 1", tResult)
answer tResult
(Using empty row and column delimiter as you only select one field in one post.)

Updating an SQLite database via an ODBC linked table in Access

I am having an issue with an SQLite database. I am using the SQLite ODBC from http://www.ch-werner.de/sqliteodbc/ Installed the 64-bit version and created the ODBC with these settings:
I open my Access database and link to the datasource. I can open the table, add records, but cannot delete or edit any records. Is there something I need to fix on the ODBC side to allow this? The error I get when I try to delete a record is:
The Microsoft Access database engine stopped the process because you and another user are attempting to change the same data at the same time.
When I edit a record I get:
The record has been changed by another user since you started editing it. If you save the record, you will overwrite the changed the other user made.
Save record is disabled. Only copy to clipboard or drop changes is available.
My initial attempt to recreate your issue was unsuccessful. I used the following on my 32-bit test VM:
Access 2010
SQLite 3.8.2
SQLite ODBC Driver 0.996
I created and populated the test table [tbl1] as documented here. I created an Access linked table and when prompted I chose both columns ([one] and [two]) as the Primary Key. When I opened the linked table in Datasheet View I was able to add, edit, and delete records without incident.
The only difference I can see between my setup and yours (apart from the fact that I am on 32-bit and you are on 64-bit) is that in the ODBC DSN settings I left the Sync.Mode setting at its default value of NORMAL, whereas yours appears to be set to OFF.
Try setting your Sync.Mode to NORMAL and see if that makes a difference.
Edit re: comments
The solution in this case was the following:
One possible workaround would be to create a new SQLite table with all the same columns plus a new INTEGER PRIMARY KEY column which Access will "see" as AutoNumber. You can create a unique index on (what are currently) the first four columns to ensure that they remain unique, but the new new "identity" (ROWID) column is what Access would use to identify rows for CRUD operations.
I had this problem too. I have a table with a primary key on a VARCHAR(30) (TEXT) field.
Adding an INTEGER PRIMARY KEY column didn't help at all. After lots of testing I found the issue was with a DATETIME field I had in the table. I removed the DATETIME field and I was able to update record values in MS-Access datasheet view.
So now any DATETIME fields I need in SQLite, I declare as VARCHAR(19) so they some into Access via ODBC as text. Not perfect but it works. (And of course SQLite doesn't have a real DATETIME field type anyway so TEXT is just fine and will convert OK)
I confirmed it's a number conversion issue. With an empty DATETIME field, I can add a time of 01-01-2014 12:01:02 via Access's datasheet view, if I then look at the value in SQLite the seconds have been rounded off:
sqlite> SELECT three from TEST where FLoc='1020';
2014-01-01 12:01:00.000
SYNCMODE should also be NORMAL not OFF.
Update:
If you have any text fields with a defined length (e.g. foo VARCHAR(10)) and the field contents contains more characters than the field definition (which SQLite allows) MS-Access will also barf when trying to update any of the fields on that row.
I've searched all similar posts as I had a similar issue with SQLite linked via ODBC to Access. I had three tables, two of them allowed edits, but the third didn't. The third one had a DATETIME field and when I changed the data type to a TEXT field in the original SQLite database and relinked to access, I could edit the table. So for me it was confirmed as an issue with the DATETIME field.
After running into this problem, not finding a satisfactory answer, and wasting a lot of time trying other solutions, I eventually discovered that what others have mentioned about DATETIME fields is accurate but another solution exists that lets you keep the proper data type. The SQLite ODBC driver can convert Julian day values into the ODBC SQL_TIMESTAMP / SQL_TYPE_TIMESTAMP types by looking for floating point values in the column, if you have that option enabled in the driver. Storing dates in this manner gives the ODBC timestamp value enough precision to avoid the write conflict error, as well as letting Access see the column as a date/time field.
Even storing sub-second precision in the date string doesn't work, which is possibly a bug in the driver because the resulting TIMESTAMP_STRUCT contains the same values, but the fractional seconds must be lost elsewhere.

How to assign an ID but then delete if not used

I am unsure on how to do this 'best practice' wise.
I have a web application (asp.net VB) that connects to an MS SQL server 2012. Currently when the page loads the app connects to a DB table and gets the last ID and adds 1 to it and displays this to the user. When the user submits the form the new ID is saved to the DB.
The problem being the app may be opened by 2 users at the same time and therefore they will get assigned the same ref number which will cause problems when the data is saved.
How can I assign different numbers to different users if the app is opened at the same time without saving unnecessary data?
You have multiple solutions for this, I'll try to outline a few approaches. (I'll assume that you need to insert things into a DB that I'll call "orders".)
First of all, you can move the ID-generation to the moment when the order is actually inserted, and not at the moment when the user start to enter the data. That way, you do not generate an ID for a user that never completes the form. Also this scenario is easy to accomplish using autoincrementing values in sql server. You can, for example do:
-- create a table with an identity column
create table Orders (
ID int identity(1,1) not null,
Description nvarchar(max) not null
);
-- insert values, without specifying the ID column
insert into Orders (Description) values ()
-- select the row back
-- returns 1, 'My First Order'
select * from Orders;
Another way to do this is to use SQL Server Sequences. These are things that do nothing except generate numbers in a row. They guarantee that the numbers won't be repeated, and always keep count of the current value, i.e.
-- create a sequence
create sequence OrderIdSequence
start with 1
increment by 1;
-- get the next sequence value
select next value for OrderIdSequence

Web Form Next Number Generation Scenario

I have a web form with several fields first field is Employee Number which is having "EMP - 0001" Format.i'm generating next Employee number by considering the last Emp Number added and converting the latter part to integer and add one
ex: split EMP - 0001 -> get 0001 -> convert it to integer -> add one -> generate next no as EMP - 0002
Next Employee Number should be visible to the user.my issue is when there are multiple users using the system.imagine that one user opens the web Form and doesn't save the record.his Employee Number is EMP - 0002.another user opens the web form he also sees the EMP no as 0002 because last record is not saved yet.2nd user saves the records he gets the Number 0002.1st user then saves the record.so at last i've got duplicate EMP Numbers in my database.what kind of scenario should i follow to over come this situation
The only way to accurately predict their ID is to put in a blank record, get the ID used, then when they enter the form, update the record with their information. However, if they quit the form, you're left with a blank record.
Insert the record on the DB and get the ID it returns. You won't have concurrency issues there if you're opening and disclosing your connection correctly.
Your current approach is prone to concurrency issues as you pointed out & I will not recommend it you. You have the following options.
Use an Identity column in your database table as a serial column (The database automatically increments the identity column on every insert row operation- you don't have to specify it through code)SQL Server Identity
Use a database sequence (Depeding on your database version & its support - A database sequence returns a unique integer value - this can also be cached, presented on form once the form loads - once generated, same sequence is never generated again)
Use a database trigger to automatically update the Id column on every row insert
Depeding on your requirement, you can pick one option.
After saving the record you can give the user message tah record is saved and your Employee numnber is "EMP - 0002".

Resources