How do I access the dBase table that was automatically opended in dBASE8? - dbase

We recently bought dBASE 8 as a replacement for Visual dBASE which no longer works in Windows 7/8 64 bit. We don't plan using it for programming but just for simple manipulations of .dbf files, like adding or deleting columns, filtering and exporting etc.
After setting up dBASE 8 to be the default program for .dbf files, double clicking a .dbf file automatically opens and displays that table.
Visual DBase used to automatically add a line to the command window like
use "c:\some\dir\table.dbf"
and any command entered into that window would work on that table. This seems to be different with dBASE 8. The line above does not get added and if I enter a command that needs a table to be open, like
set filter to strasse="blablub"
I get the file open dialog.
Is there any way to get the "old" behavior back? Or is there any simple way to switch to the table that is already being displayed without having to type the name again or selecting it in the file open dialog?

I got an answer in the dbase newsgroup that solves part of the problem
This program
**********************
* GrabBrowse.prg
* Catches the table that was opened in an instance of PLUS
* by double-clicking on a table in Windows Explorer.
* Sets the query as _app.q.
* Reports the tablename.
* Returns the query.
* Opens the table with USE.
private q
q = findinstance("query")
? q.rowset.tablename
_app.q = q
if not empty(findinstance("query", q))
msgbox("There is more than one query active: ";
+ findinstance("query", q).rowset.tablename ;
+ chr(13) + "But still put in _app.q and USEd.", ;
"GrabBrowse", 48)
endif
use (q.rowset.tablename)
return (q)
**********************
stored in a text file in the dBASE search path and called with
do GrabBrowse
switches to the table so any commands will affect that table.
e.g.
set filter to strasse="blablub"
will set the filter for that table. Unfortunately this does not affect the browse window that is already open but only one that is opened afterwards.
But it's a partial solution.

Related

comparing two BLOB statements in SQLite using SQLiteStudio

I am currently working on a warehouse management system operated on a Raspberry Pi. Scanning a QR code should open the correct line of the database.
I read the text file/CSV file containing the QR code into my Table QR database via:
insert into QR values(readfile("C:\...\IDNumberfromQR.csv"));
this works, because the ID number appears in the database in the correct table. However, the content of the text file is read in the file type "Blob".
If I now make a table comparison via
SELECT * from warehouse management table
where PulverID=( select code from QR);
nothing appears.
However, if I enter the ID number on the computer in the table QR.code and do not have the ID read in via my file, the line I am looking for appears. So it is obviously a Data format problem.
What I already tried:
I have already set both to blob in the settings. This still did not work. The functions found in the SQLiteStudio tutorial like import(file,format,table) don't work either.
Does anyone have any idea how i can solve this problem?
Is it possible to read a CSV file as double?

How can we insert an image in sqlite database(table)?

I guess that it's valid for MySQL, however, I cannot find anything about SQLite.
Basically, I have a table which is named 'CUSTOMER'.
So I create an attribute like this:
.. Image BLOB .. after that my insert statement looks like this:
INSERT INTO CUSTOMER(1,LOAD_FILE(D:/Project/Images/X.jpg));
However, the LOAD_FILE tag is not working and I don't know how to insert an image or if we can do that.
If you're using the sqlite3 shell, the relevant function is readfile().
If you're doing this from your own program, you have to read the file into a byte array and bind it as a blob to the desired column in an insert. The exact details vary depending on language and sqlite bindings, but you shouldn't ever have to convert it to a blob literal string and embed that directly into a statement.
You can store an image as a BLOB, but you'd have to insert it as a a series of bytes using something like :-
INSERT INTO CUSTOMER (image_column, other_column) VALUES(x'0001020304........','data for the first other column');
So you'd need to convert the file into a hex string to save it.
However, it's not really recommended to store images but to rather store the path to the image and then retrieve the file when you want to display/use the image.
Saying that, SQLite can, for smaller images (say 100K), actually be more efficient 35% Faster Than The Filesystem.
You must use the cmd command line (windows) to insert the attachment. The sqllitespy (version 1.9.13) does not support de command from the program command line.
You should acess you database first with the CMD and after that;
update (your table) set (column) = readfile ('dir where the files are stored'||num||ยด.jpg);

Replace part of a string in sqlite

I recently moved my mp3 library to my home folder, and this caused banshee to forget my file data (such as rating, ect). If I can update the file path in banshee's sqlite table, I can get restore my user-entered file data.
sqlite stores path data in a Uri field of the CoreTracks table.
Example:
Uri
file:///storage/Music/mp3/Genre/Artist/Album/Track.mp3
I'd like to change all instances to
file:///home/user/Music/mp3/Genre/Artist/Album/Track.mp3
Is there a safe way of changing just the first 15 characters of data contained in the Uri field?
Create the database backup. Then use the sqlite.exe command line shell. open your database like this:
sqlite rating.sqlite
> UPDATE CoreTracks SET Uri = 'file:///home/user' + substr(Uri, 17);
>
At the end press Ctrl-D to finish the sqlite console. I think I counted the characters correctly. Please double check if value 17 needs to be changed to something else

Sqlite: Create a table and fill with information only once

I have an appcelerator titanium project (you don't need to be familiar with the platform to help me) that I am using to create an iOS app. I want to have a database with a table that is filled with several rows for the first time, and then left alone after the first time.
I know you can create a table if it doesn't exist. Is there something similar for Inserting data?
Thanks!
Expanding on MPelletier's response with some Titanium-specific code, you could do the following in your project:
var my_db = Ti.Database.open('nameofdb');
var my_result_set = my_db.execute('SELECT * FROM MyTable');
var records = my_result_set.rowCount;
The records variable will indicate whether or not you have data in your table and then you can act accordingly.
There are a couple of nice ORM-ish utilities out there for Titanium: TiStore and Joli are the two I've used. Both are inspired by ActiveRecord and can be helpful in reducing your DB-related code. They're on Github if you want to know more about them!
There's INSERT OR REPLACE if you want, but you might as well just check against the number of rows on the table:
SELECT COUNT(*) FROM MyTable;
Then decide to enter them on that.
You can create your DB and insert data in it via SQLLiteManager or whatever tool you want and then dump it.
Take the file you dumped, put it in your Titanium project folder (somewhere in the Resources folder).
Then this line of code will take the content of the .sqlite file and insert it in the iOS db:
var db = Ti.Database.install('../your-db.sqlite', 'your-db-name');
Just don't forget the CREATE IF NOT EXISTS statement in your SQL file.
Or use REPLACE instead of INSERT as MPelletier said.

The Ghost of a Renamed Table

I have renamed a table in a SQL Server 2008 database, from eL_CourseStepUserNotes to StepUserNotes. I renamed the table using the SSMA.
The table is used in a ASP.NET 4.0 app. I use LINQ to SQL for all CRUD. The problem is that the following code:
dbDataContext db = new dbDataContext();
var k = (from c in db.StepUserNotes
where ((c.CourseStepFK == q.CourseStepFK) && (c.UserFK == q.UserFK))
select c).FirstOrDefault();
try
{
db.StepUserNotes.InsertOnSubmit(q);
db.SubmitChanges();
}
catch
{
}
Fails on the db.SubmitChanges line, saying:
SqlException was caught. Invalid object name 'eL_CourseStepUserNotes'.
Ie, the old name for the table has come back to haunt me.
I have deleted the old LINQ to SQL dbml file and created a new one. I have searched through all the source code for strings that contain the old table name. Nothing. The code compiles...
Where else can I look?
The error is coming back from SQL Server, and using the utility for listing all foreign keys in a sql server database shown in SO question:
sql:need to change constraint on rename table?
reveals no sign of the old table name in FKs either.
I am at a complete loss as to where to look or what to try next. Any suggestions?
Answer:
The problem, as stated by Stu and Stark was a trigger. Stu gave me the SQL to run that nailed the problem. It is documented here in case anyone else runs into this:
Select Object_Name(ID) From SysComments
Where Text Like '%el_CourseStepUserNotes%'
This revealed a trigger with the following name:
tr_eL_CourseStepUserNotes
The trigger referenced the old name as follows:
SET DateAmended = CURRENT_TIMESTAMP
FROM eL_CourseStepUserNotes PP
INNER JOIN inserted i ON PP.UserNoteId = i.UserNoteId
Everything is now working again.
Silly me, I should have realised that a trigger was the problem as the first error I got was related to the DateAmended field.
I have no idea why a trigger would update when a table name changed. I had checked all Keys and relationships, but forgot this trigger.
Live and learn.
When you recreated your linq to sql file, did you remember to refresh the server browser to reflect the table name change first?
Edit - I mean the visual studio server browser.
you need to rebind your LINQ To SQL class, drop all the tables, then add them again from the Server Explorer
open your project in visual studio.
open your dbml file.
find the table you just have renamed.
select and delete it.
Save.
Open server Explorer.
Connect to your database.
Find the table which you have renamed.
Drag and drop on the designer of your dbml file.
Save the file again.
Compile your project.
It is not necessary to drop the tables from your DBML file. You can simply open the designer, click on the class diagram representing your table and type the new name of the table.
However, if you're recreating from scratch it is important to refresh in Server Explorer otherwise it will still pull the old name from the schema.

Resources