Creating charts from sql files - sql

I have a sql file containing information about a potential clients website keywords. I have exported this file from an ipad SEO app and got a sql file. I would like be able to show the information as charts or tables but Ive never worked with this file format before. Are there any good programs that can do this or is this a "hardcore programer task"?
Thank you!
Few lines taken from the sql file
SQLite format 3# Ô Ô-‚%
‡‡bgÅÅ_tabledomainsdomainsCREATE TABLE domains (domain_name varchar(100), id INTEGER PRIMARY KEY, sort integer, country varchar(2))Å--Ågtablekeywords_historykeywords_historyCREATE TABLE keywords_history (position integer, date_added varchar(10), id INTEGER PRIMARY KEY, kid integer)^ÅatablekeywordskeywordsCREATE TABLE keywords (sort integer, domain_id integer, id INTÅÇ tablekeywordskeywordsCREATE TABLE keywords (sort integer, domain_id integer, id INTEGER PRIMARY KEY, keyword_text varchar(500), country varchar(2))
ÉÓ◊¬∞ñÉliving.seSE-unifiedsweden.seSEes√§k.seSE#virotell.seSE) mediaanalys.seSEapple.comUS˚˚≤£ìiT6 Ï› ¥ûÑo]D%÷¡•ëvW1·ƒ®˛ãtV)1hallm√∂bler malm√∂SE(#hallm√∂blerSE'/f√•t√∂ljer malm√∂SE%-belysning malm√∂SE#/
inredningskonsultSE"3heminredning malmöSE!%
heminredningSE$belysningSE$Aträdgårds möbler malmöSE3
trädgårds möblerSE+ soffbord malmöSEsoffbordSE-köksbord malmöSEköksbordSE$Avardagsrums möbler malmöSE&!fåtöljerSEsoffaSE3vardagsrums möblerSE )möbler malmöSEmöblerSE visitkortSE)webbutvecklingSE!webbdesignSE!web designSEadwordsSE
ppcSE
/sponsrade länkarSE
seoSE 3sökmarknadsföringSE
3sökmotoroptimeringSE !värmepumpSE!abonnemangSEvirotellSE mobilSE
teleSE
ppcSE 3s√∂kmotoroptimeringSEseoSE apple )˚˚∏•íÄn\J9&Ì⁄»∂§íÄn\J8&Ó€…∑•ìÅo]K9'ÒfiÀ∏¶îÇp2!2013-02-07
1!2013-02-070!2013-02-07/!2013-02-07
.! 2013-01-24-!2013-01-24,!)2013-01-24+!2013-01-24
*!2013-01-24)!2013-01-24(!2013-01-24
'!2013-01-23&!2013-01-23%!2013-01-23
$!2013-01-23#!2013-01-23"!2013-01-23
!!2013-01-11
!2013-01-11!2013-01-11! 2013-01-11!2013-01-11!)2013-01-11!2012-12-24!2012-12-24!2012-12-24!2012-12-24!2012-12-24!2012-12-24!2012-12-24
!2012-12-24!2012-12-24!2012-12-24
!2012-12-19 ! 2012-12-19!2012-12-19!%2012-12-19
!2012-12-16!'2012-12-16 ! 2012-12-16
!2012-12-16 !2012-12-16!2012-12-16!2012-12-16!2012-12-16!2012-12-14!)2012-12-14 ! 2012-12-14! 2009-06-05! #2009-2
2pÓ‹À∏•íÄn\J9&Ì⁄»∂§íÄn\J8&Ó€…∑•ìÅo]K9'ÒfiÀ∏¶îÇp2!2013-02-07
1!2013-02-070!2013-02-07/!2013-02-07
.! 2013-01-24-!2013-01-24,!)2013-01-24+!2013-01-24
*!2013-01-24)!2013-01-24(!2013-01-24
'!2013-01-23&!2013-01-23%!2013-01-23
$!2013-01-23#!2013-01-23"!2013-01-23
!!2013-01-11
!2013-01-11!2013-01-11! 2013-01-11!2013-01-11!)2013-01-11!2012-12-24!2012-12-24!2012-12-24!2012-12-24!2012-12-24!2012-12-24!2012-12-24
!2012-12-24!2012-12-24!2012-12-24
!2012-12-19 ! 2012-12-19!2012-12-19!%2012-12-19
!2012-12-16!'2012-12-16 ! 2012-12-16
!2012-12-16 !2012-12-16!2012-12-16!2012-12-16!2012-12-16!2012-12-14!)2012-12-14 ! 2012-12-14! 2009-06-05! #2009-06-01
!¶Ó‹ ∏¶îÇo]K'›À∏î¶Å9o]J8%Ó‹ ∏¶U!2013-02-180T!2013-02-18/S!2013-02-18.R!2013-02-18-Q!2013-02-18,P!2013-02-18+O!2013-02-18*N!
2013-02-18)M!2013-02-18(L!2013-02-18'K!2013-02-18&J!2013-02-18%H!2013-02-18#F!2013-02-18!G!2013-02-18"D!+2013-02-18C!2013-02-18B!2013-02-18A!2013-02-18#!2013-02-18?!2013-02-18>!2013-02-18I!2013-02-18$<!2013-02-18;!2013-02-18:!
2013-02-189!2013-02-188!2013-02-077!2013-02-076!2013-02-075!2013-02-074!2013-02-073!2013-02-07
'VÌfl¡≤£ìiT6 Ï› ¥ûÑo]D&÷¡•ëvW1·ƒ®˛ãtV)1hallm√∂bler malm√∂SE(#hallm√∂blerSE'/f√•t√∂ljer malm√∂SE%-belysning malm√∂SE#/
inredningskonsultSE"3heminredning malmöSE!%
heminredningSE$belysningSE$Aträdgårds möbler malmöSE3
trädgårds möblerSE+ soffbord malmöSEsoffbordSE-köksbord malmöSEköksbordSE$Avardagsrums möbler malmöSE&!fåtöljerSEsoffaSE1vardagsrumsmöblerSE )möbler malmöSEmöblerSE visitkortSE)webbutvecklingSE!webbdesignSE!web designSEadwordsSE
ppcSE
/sponsrade länkarSE
seoSE 3sökmarknadsföringSE
3sökmotoroptimeringSE !värmepumpSE!abonnemangSEvirotellSE mobilSE
teleSE
ppcSE 3sökmotoroptimeringSEseoSE apple macUS
[Ì”¡®ñ|[07sovrumsm√∂bler malm√∂SE/)sovrumsm√∂blerSE.sovrumSE-'mattor malm√∂SE,mattorSE+)matbord malm√∂SE*matbordSE

JFreeChart is a useful Java library for chart generation. While I've never used it with a sql file, I believe that it is possible.

The file seems to be a SQLLite file which represents a database. To be able to use it, you need to install a SQLLite database browser like this one. I think you may have to change the file extension to .db to be able to open it. If this works, I think your best bet would be to view the table data, and copy and paste it into excel or some similar program you are familiar with to create the chart.

Related

Is there a more efficient way to parse a fixed txt file in Access than using queries?

I have a few large fixed with text files that have multiple specification formats in them. I need to parse out the txt files based on a character with a set location in the file. That character can have a different position in the file.
I have written queries for each of the different specifications (95 of them) with the start position and length hard coded into the query using the mid() function with a WHERE() function to filter the [Record Identifier] from the specification. As you can see below the 2 specifications in the WHERE() function have different placements in the txt file.
\\\
SELECT Mid([AllData],1,5) AS PlanNumber, Mid([AllData],6,4) AS Spaces1, Mid([AllData],10,3) AS Filler1, Mid([AllData],13,11) AS SSN, Mid([AllData],24,1) AS AccountIdentifier, Mid([AllData],25,5) AS Filler2, Mid([AllData],30,2) AS RecordIdentifier, Mid([AllData],32,1) AS FieldType, Mid([AllData],33,4) AS Filler3, Mid([AllData],37,8) AS HireDate, Mid([AllData],45,8) AS ParticipationDate, Mid([AllData],53,8) AS VestinDate, Mid([AllData],61,8) AS DateOfBirth, Mid([AllData],77,1) AS Spaces2, Mid([AllData],78,1) AS Reserved1, Mid([AllData],79,1) AS Reserved2, Mid([AllData],80,1) AS Spaces3
FROM TBL_Company1
WHERE (((Mid([AllData],30,2))="02") AND ((Mid([AllData],32,1))="D"));
\\\
Or
\\\
SELECT Mid([AllData],1,5) AS PlanNumber, Mid([AllData],6,4) AS Spaces1, Mid([AllData],10,3) AS Filler1, Mid([AllData],13,11) AS SSN, Mid([AllData],24,1) AS AccountIdentifier, Mid([AllData],25,7) AS RecordIdentifier, Mid([AllData],32,22) AS StreetAddressForBank, Mid([AllData],54,20) AS CityForBank, Mid([AllData],74,2) AS StateForBank, Mid([AllData],76,5) AS ZipCodeForBank
FROM TBL_Company1
WHERE (((Mid([AllData],25,7))="49EFTAD"));
\\\
Is there a way to Parse out this without having to hard code every position and length into the code?
I was thinking of having a table with all of the specifications in it and have an import function look to the specification table and parse out the data accordingly to a new table or maybe something else.
What I have done is not very scalable and if the format changes a little I would have to go back to each query to change it.
Any Help is greatly appreciated
I think in your situation, I'd want to be able to generate the SQL statement dynamically, as you suggest.
I'd have a table something like:
Format#,Position,OutColName,FromPos,Length,WhereValue
1,1,"PlanNumber",1,5,
1,2,"Spaces1",6,4,
...
1,n,,30,2,"02"
1,n+1,,32,1"D"
and then some VBA to process it and build and execute the SQL string(s). The SELECT clause entries would be recognized by having a value in the OutColName field and WHERE clause entries by values in the the WhereValue column.
Of course this is only more "efficient" in the sense that it's a bit easier to code up new formats or fix/modify existing ones.

Flask and sqlite3 - does a table need to be populated with data before the 'insert into' sql command can work?

When creating a flask site with sqlite3, I noticed that if I tried to INSERTINTO (using a web-form) the database, when the database was empty, it wouldn't produce an error, but nothing would happen, the INSERT INTO (SQL) would simply not take effect.
I had to manually populate the database using a pre-made query, and then, without changing anything else in the code, the inserting-into the form worked fine.
Can anyone shed any light as to why this might have happened? I assume it isn't necessary for a database to be populated in order for it to be used/functional in flask/sqlite3.
I wondered if it had anything to do with my setup.
create-db.py
import sqlite3
db_locale='users.db' #flask will create this db if it doesn't exist
connie=sqlite3.connect(db_locale)
c=connie.cursor() #used to create commands
c.execute("""
CREATE TABLE comments
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT,
name TEXT,
comments TEXT
)
""")
connie.commit()
connie.close()
The addcomment() and insertcomment() methods in the main .py file
def addcomment():
if request.method=="GET":
return render_template('addcomment.html')
else:
user_details=(
request.form['title'],
request.form['name'],
request.form['comments']
)
insertcomment(user_details)
return render_template('addsuccess.html')
def insertcomment(user_details):
connie=sqlite3.connect(db_locale)
c=connie.cursor()
sql_execute_string='INSERT INTO comments (title,name,comments) VALUES (?,?,?)';
c.execute(sql_execute_string,user_details)
connie.commit()
connie.close()
print(user_details)

Cannot bring back all occurrances of a substring when i know more than one exists(TSQL)

I'm searching against a database, in which it has two tables. A table containing the ID, and a table which holds a large data string (i.e. application data, which is in JSON format if it makes any difference).
The Data looks something like this:
ID AppData
------- ----------------------
1111 {"$type":"Apply.Domain.Model","ThumbnailId":"c5948e9d-1111","FileName":"image06.jpg","Id":"cc3b21b5-4dc3-481e-ba06-7ee1a4caf51d"},{"$type":"Apply.Domain.Model","ThumbnailId":"c5948e9d-2222","FileName":"dispesn_image.jpg","Id":"cc3b21b5-4dc3-481e-ba06-7ee1a4caf51d"}
2222 {"$type":"Apply.Domain.Model","ThumbnailId":"4494329d-1111","FileName":"anIMAGe_232.jpg","Id":"cc3b21b5-aaa-481e-ba06-7434344af51d"},{"$type":"Apply.Domain.Model","ThumbnailId":"c5948e9d-2222","FileName":"anIMAGe_232.jpg","Id":"aaa2235-4dc3-481e-ba06-7ee1a4caf51d"}
I'm trying to find within this application data, sub-strings which are image file names,of which there could be more than one and output them as such:
ID ImageName
--- ---------
1111 image06.jpg
1111 dispesn_image.jpg
2222 anIMAGe_232.jpg
2222 anIMAGe_232.jpg
I know ALL the file names in the appdata column will be contained within this specific string(quotation marks included):
"FileName":"anIMAGe_232.jpg","Id"
and I am currently able to extract the image file name (with some "quirks")using this
declare #firststring varchar(max), #secondstring varchar(max)
set #firststring = 'FileName":"'
set #secondstring = '","Id":"';
select SUBSTRING(SerializedFormData, CHARINDEX(#firststring, SerializedFormData),
CHARINDEX(#secondstring, SerializedFormData) - CHARINDEX(#firststring, SerializedFormData))
this brings me back my image name:
FileName":"IMAGENAME.jpg
Brilliant, except My first quirk is that I can't seem to display it excluding the first bit 'Filename":" ' (This particular issue has since been resolved thanks to JohnHC but kept in for future reference).
The second is that this query doesn't seem to search through the whole appdata string, and as such only brings back the first instance it comes across i.e.
ID ImageName
--- ---------
1111 image06.jpg
2222 anIMAGe_232.jpg
Any ideas as to why it won't search through the whole string?
much appreciation for any help given :)
Regards
First problem, you're pulling back the CHARINDEX from #Firststring as your start (ie, where it finds 'Filename'. You need to use:
...CHARINDEX(#firststring, SerializedFormData)+ LEN(#firststring)...
Second, this will only work on the first iteration. Smarter minds (with more free time) will be able to point you in the direction of how best to resolve issue 2.

SQL Server : remove duplicated text within a string

I have a SQL Server 2008 table with a column containing lengthy HTML text. Near the top there is a link provided for an associated MP3 file which is unique to each record. The links are are all formatted as follows:
<div class="MediaSaveAs">Download Audio </div>
Unfortunately many records contain two or three sequential and identical instances of this link where there should be only one. Is there a relatively simple script I can run to find and eliminate the redundant links?
I'm not entirely sure - because your explanation wasn't very clear - but this appears to do what you want, although whether or not you consider this to be a "simple script", I don't know.
declare #Link nvarchar(200) = N'<div class="MediaSaveAs">Download Audio </div>'
declare #BadData nvarchar(max) = N'cbjahcgfhjasgfzhjaucv' + replicate(#Link, 3) + N'cabhjcsghagj',
#StartPattern nvarchar(34) = N'<div class="MediaSaveAs"><a href="',
#EndPattern nvarchar(27) = N'">Download Audio </a></div>'
select #BadData
select replace (
#BadData,
substring(#BadData, charindex(#StartPattern, #BadData), len(#BadData)-charindex(reverse(#EndPattern), reverse(#BadData))-charindex(#StartPattern, #BadData) + 2),
substring(#BadData, charindex(#StartPattern, #BadData), charindex(#EndPattern, #BadData) + len(#EndPattern) - charindex(#StartPattern, #BadData))
)
Personally I would not like to have to maintain this code; I would far rather use a script in another language that can actually parse HTML. You said this is "just a repeated text issue", but that doesn't mean it's an easy problem and especially not in a language like TSQL that has such limited support for string operations.
For future reference, please put all relevant information into the question - you can edit it if you need to - instead of leaving them in the comments where they are difficult to read and may be overlooked. And please post sample data and results instead of describing things in words.
First we need to identify the file names, which we can do with PATINDEX:
select
substring(html, PATINDEX('%filename%.mp3%', html), PATINDEX('%.mp3%', html)-PATINDEX('%filename%.mp3%', html)+4)
from files
And then secondly identify and the duplicates, check it out:
delete
from files
where id not in (
select max(id)
from files
group by substring(html, PATINDEX('%filename%.mp3%', html), PATINDEX('%.mp3%', html)-PATINDEX('%filename%.mp3%', html)+4)
)
http://www.sqlfiddle.com/#!3/887a3/5

MOSS 2007: What is the source of "Directories"?

I'm trying to generate a new SharePoint list item directly using SQL server. What's stopping me is damn tp_DirName column. I have no ideas how to create this value.
Just for instance, I have selected all tasks from AllUserData, and there are possible values for the column: 'MySite/Lists/Task', 'Lists/Task' and even 'MySite/Lists/List2'.
MySite is the FullUrl value from Webs table. I can obtain it. But what about 'Lists/Task' and '/Lists/List2'? Where they are stored?
If try to avoid SQL context, I can formulate it the following way: what is the object, that has such attribute as '/Lists/List2'? Where can I set it up in GUI?
Just a FYI. It is VERY not supported to try and write directly to SharePoint's SQL Tables. You should really try and write something that utilizes the SharePoint Object Model. Writing to the SharePoint database directly mean Microsoft will not support the environment.
I've discovered, that [AllDocs] table, in contrast to its title, contains information about "directories", that can be used to generate tp_DirName. At least, I've found "List2" and "Task" entries in [AllDocs].[tp_Leaf] column.
So the solution looks like this -- concatenate the following 2 components to get tp_DirName:
[Webs].[FullUrl] for the web, containing list, containing item.
[AllDocs].[tp_Leaf] for the list, containing item.
Concatenate the following 2 components to get tp_Leaf for an item:
(Item count in the list) + 1
'_.000'
Regards,
Well, my previous answer was not very useful, though it had a key to the magic. Now I have a really useful one.
Whatever they said, M$ is very liberal to the MOSS DB hackers. At least they provide the following documents:
http://msdn.microsoft.com/en-us/library/dd304112(PROT.13).aspx
http://msdn.microsoft.com/en-us/library/dd358577(v=PROT.13).aspx
Read? Then, you know that all folders are listed in the [AllDocs] table with '1' in the 'Type' column.
Now, let's look at 'tp_RootFolder' column in AllLists. It looks like a folder id, doesn't it? So, just SELECT the single row from the [AllDocs], where Id = tp_RootFolder and Type = 1. Then, concatenate DirName + LeafName, and you will know, what the 'tp_DirName' value for a newly generated item in the list should be. That looks like a solid rock solution.
Now about tp_LeafName for the new items. Before, I wrote that the answer is (Item count in the list) + 1 + '_.000', that corresponds to the following query:
DECLARE #itemscount int;
SELECT #itemscount = COUNT(*) FROM [dbo].[AllUserData] WHERE [tp_ListId] = '...my list id...';
INSERT INTO [AllUserData] (tp_LeafName, ...) VALUES(CAST(#itemscount + 1 AS NVARCHAR(255)) + '_.000', ...)
Thus, I have to say I'm not sure that it works always. For items - yes, but for docs... I'll inquire into the question. Leave a comment if you want to read a report.
Hehe, there is a stored procedure named proc_AddListItem. I was almost right. MS people do the same, but instead of (count + 1) they use just... tp_ID :)
Anyway, now I know THE SINGLE RIGHT answer: I have to call proc_AddListItem.
UPDATE: Don't forget to present the data from the [AllUserData] table as a new item in [AllDocs] (just insert id and leafname, see how SP does it itself).