VB.Net Query CSV File - vb.net

I have a a csv file I need to process to find just a few line items. I followed the tutorial here for reading in a CSV file into a DataTable. It worked very well when my query was:
SELECT * FROM <NameOfCsvFile>
This is great but it returns the whole CSV file as a DataTable. I only want a portion of the file to check for known errors. So I modified my query to be like this:
SELECT * FROM <NameOfCsvFile> WHERE Column1 IN (Int1,Int2,Int3,Int4,Int5)
When I checked the DataTables output in the debugger it had the right row count (being 5) but the list of rows was equal to NOTHING.
How can I get this to work MS's query interface instead of manually looping through the whole CSV file to return the 5 records I seek out of hundreds?

I figured it out. The query worked perfectly but the debugger doesn't allow you to see what rows are returned as they haven't been decoded yet. Calling Dim rows() as DataRows = dt.Select("") allowed me to see the actual results of the CSV file query.
All is good in the world now

Related

SQLPlus Won't Display Columns In CSV When No Results Returned

In SQL Plus I am using "spool" and "set markup csv on" to send sql SELECT queries to csv files on my computer.
This all works well enough, except when a query generates zero results, it doesn't display the column headings. It just says 'no results returned,' but I still need it to show the column names in that case.
How can I change this?

Query for finding all occurrences of a string in a database

I'm trying to find a specific string on my database. I'm currently using FlameRobin to open the FDB file, but this software doesn't seems to have a properly feature for this task.
I tried the following SQL query but i didn't work:
SELECT
*
FROM
*
WHERE
* LIKE '126278'
After all, what is the best solution to do that? Thanks in advance.
You can't do such thing. But you can convert your FDB file to a text file like CSV so you can search for your string in all the tables/files at the same time.
1. Download a database converter
First step you need a software to convert you databse file. I recommend using Full Convert to do it. Just get the free trial and download it. It is really easy to use and it will export each table in a different CSV file.
2. Find your string in multiple files at the same time
For that task you can use the Find in files feature of Notepad++ to search the string in all CSV files located at the same folder.
3. Open the desired table on FlameRobin
When Notepad++ highlight the string, it shows in what file it is located and the number of the line. Full Convert saves each CSV with the same name as the original table, so you can find it easily whatever database manager software you are using.
Here is Firebird documentation: https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25.html
You need to read about
Stored Procedures of "selectable" kind,
execute statement command, including for execute statement variant
system tables, having "relation" in names.
Then in your SP you do enumerate all the tables, then you do enumerate all the columns in those tables, then for every of them you run a usual
select 'tablename', 'columnname', columnname
from tablename
where columnname containing '12345'
over every field of every table.
But practically speaking, it most probably would be better to avoid SQL commands and just to extract ALL the database into a long SQL script and open that script in Notepad (or any other text editor) and there search for the string you need.

How to use Vertica's COPY LOCAL as an sql statement from MATLAB on Windows

I'm trying to insert around 80 million records created using MATLAB into Vertica Database table. I wanted to know if we can call COPY LOCAL statement in MATLAB as a regular sql statement using exec(conn, sql). For test purpose, I tried with a dat file having around 4 million records as following:
sqlstmnt = 'COPY schema.table_name (FK_CUSTOMER_ID,FK_RUN_START_DATE_ID,FK_RUN_END_DATE_ID,FK_TRAVEL_ID,FK_ORIGIN_ID,FK_DEST_ID,FK_SEGMENT_ID,SEGMENT_PERCENTAGE,LAST_UPDATED) FROM LOCAL ''/my/file/full/path/test1.dat''';
results = exec(conn,sqlstmnt);
But it gave an error in results.Message like:
[Vertica]JDBC A ResultSet was expected but not generated from query "COPY schema.table_name(FK_CUSTOMER_ID,FK_RUN_START_DATE_ID,FK_RUN_END_DATE_ID,FK_TRAVEL_ID,FK_ORIGIN_ID,FK_DEST_ID,FK_SEGMENT_ID,SEGMENT_PERCENTAGE,LAST_UPDATED) FROM LOCAL '/my/file/full/path/test1.dat'". Query not executed.
I have the data in the '.dat' file in the order in which the columns are mentioned in COPY LOCAL.
I could not find any helpful resource explaining this error.
I have this test1.dat file which I'm able to insert using COPY from vsql but since I run my codes in MATLAB with many iterations,each iteration producing about a million records, I would want to insert them during each iteration. Any help will be really great.
COPY command return ResultSet that includes the amount of loaded data , i see two main options
1) results =exec(conn,sqlstmnt);
2)results = runsqlscript(conn,'nameOfSQLScriptthatIncludeTheCopyCommand.sql')
I hope you will find it useful
Thanks
I just finish reviewing you’re your input sample data .
i see major problem with the mapping of the input csv to the target table .
Main issues are :
1) Lines are broken into 2 lines ( you should prefer having one sample per line and avoid brock it into 2 lines )
Eg : "1,20150101,0,2,2573,2714,1,8.147237e-01
50,48,49,54,45,48,51,-28 12:11:46"
2) when you define data types on vertica table ,eg: timestamp the data on the csv must reflect to it ( what you have is "-28 12:11:46" , this will not work )
After you fix all this issues , make sure you test it using vsql , then go and try it with matlab
I hope you will find it useful.

CSV data set config just working for 1 line

I have recorded a script, in that script only a search id is changed after login and search a field
After recording i modified the script and i have provided a "CSV_Data Set COnfig" file to read a list of search ids.
The issue is
If i provide only one search id in that csv that is run correctly, but if i add multiple search ids in that file and run the script that number of time, only the first line run for that X number of times, but in Jmeter it shows that the URL of the search id was made correctly.
Can someone guide?
I have used loop controller too to run X number of times for that search ids, but same is the result.
How can i run that? (As i recorded the script 1 time and just modified that search id with csv)
The script is working fine for 1 search id, but not for multiple (after providing the search ids through csv file through csv data set config)
What i am doing wrong? please guide
It looks like you have the csv and the loop controller at the same level.
You should put the csv data set configuration as a child of loop controller
*--thread Group
*----loopcontroler
*------csv
*------httpsampler

How can I extract the value of a varbinary(max) column?

I have a varbinary(max) column that is storing images in an SQL database.
I am working on a newdb script, where an application creates a new instance of the db and populates a few of the tables. One of those tables I am working on is initializing that image column.
In order to do this, I printed the contents of the column using a select statement and pasted the content into the insert statement of the newdb script. This appeared to work initially, but the image didn't load correctly.
So I compared the DATALENTH() of the original data (5469988) and the new data (21839). It appears the Microsoft SQL Server management Studio - 2014 cut off the data why I copied it from the original db at a certain point. I need to be able to get the entire content of the column. Any ideas?
select cast(convert(varchar(max), VarBinaryMaxColumn, 1) as xml) from Table
Instead of copying/pasting, right-click on the results and do 'Save Results As...', and that should export the full contents. Funny thing is setting the query output to text or file explicitly will still truncate long data values.
If you copy and paste your limited to the query result options. Mostly columns will be cut of after a certain lenght (often 256 chars).
You can select in the top bar "save result as..." which will prompt you an dialog for data export.
You can use the data export wizard too.