Import CSV to localhost error on import - mysql

I am having some issues with an error message that keeps coming up and I cannot locate why.
I am trying to build a process that utilises the database functionalities of WAMP on my PC to store and manipulate data rather than use MS Access.
The script below contains the current powershell script that I have been working on which is creating a new database and table to contain my CSV data however when I am trying to insert the CSV data into the newly created table it is presenting me with two repetitive errors.
The property 'CommandText' cannot be found on this object. Verify that the property exists and can be set.
And
Cannot convert value ",'" to type "System.Int32". Error: "Input string was not in a correct format."
I am simply at a loss to how to correct this and why it is throwing errors, is this obvious to anyone?
$CL2Location = 'L:\Controls\BROKER CASH RECONCILIATIONS\cl2cashpositions-331-Corrected.csv'
$dbnameone = "brokerreconciliation"
[system.reflection.assembly]::LoadWithPartialName("MySql.Data")
$mysqlConn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection
$mysqlConn.ConnectionString = "SERVER=localhost;DATABASE=brokerreconciliation;UID=root;PWD=''"
$mysqlConn.Open()
$ccmd = New-Object MySql.Data.MySqlClient.MySqlCommand
$ccmd.Connection = $mysqlConn
$ccmd.CommandText = "DROP DATABASE IF EXISTS " + $dbnameone
$ccmd.ExecuteNonQuery()
$ccmd.CommandText = 'CREATE SCHEMA `' + $dbnameone + '`'
$ccmd.ExecuteNonQuery()
$dbonetablescript = #"
CREATE TABLE brokerreconciliation.CL2 (
`ID` MEDIUMINT(8) unsigned NOT NULL auto_increment,
`CL2ACCOUNTCODE` varchar(255) default NULL,
`ACBALANCE` varchar(255) default NULL,
`PARNAME1` varchar(255) default NULL,
PRIMARY KEY (`ID`)
) AUTO_INCREMENT=1;
"#
$ccmd.CommandText = $dbonetablescript
$ccmd.ExecuteNonQuery()
$ccmd = New-Object MySql.Data.MySqlClient.MySqlCommand
$ccmd.Connection = $mysqlConn
$ccmd.CommandText = "truncate table " + $dbnameone + ".CL2;"
$ccmd.ExecuteNonQuery()
foreach ($i in Import-Csv $cl2location) {
$cmd.CommandText =
"INSERT INTO customers (id,cl2accountcode,acbalance,parname1) VALUES ("
+$i.id+",'"+$i.cl2accountcode+"','"+$i.acbalance+"','"+$i.parname+"');"
$cmd.ExecuteNonQuery()
}
Import-Csv $CL2Location ##Added to ensure that the data file was being reached it is
$mysqlConn.Close()
Link to example CSV data is here.
Trying to resolve this problem I have tried to write the data directly from the data table created via the initial sql query to reduce the amount of steps that I would require. The code below is the update, even utilising the result set directly I am still hitting the same errors when I try to upload the data to local host.
I have also edited the CREATE TABLE element to match the schema of the base database exactly to ensure there was nothing with this that was causing the issue.
I am still at a loss as to how I cannot pass the information from either CSV or script to a newly created table on localhost.
[System.Reflection.Assembly]::LoadWithPartialName("Sql.Data")
$null = [Reflection.Assembly]::LoadWithPartialName("WindowsBase")
#####################
## - CREDENTIALS - ##
#####################
$MISA = 'xx.xx.x.xx'
$userName = 'IR'
$PassWord = 'IR'
$DB = 'IR'
$timeout = 0
###### - StopWatch - ######
$timeout2 = new-timespan -Minutes 5
$sw = [diagnostics.stopwatch]::StartNew()
##### sql ####
### MIS CL2 ###
$CL2CashPositionsScript = #'
SELECT CL2ACCOUNTCODE, sum(CAST(CL2ACCOUNTBALANCE AS MONEY)) AS CBALANCE, PARNAME1
FROM T5CASHL2 CL2 LEFT OUTER JOIN T5PARTICIPANT PAR
ON PAR.PARPDRPARTICIPANTID = CL2.CL2ACCOUNTCODE
WHERE CL2CLIENTNUM not like '315'
--AND CL2ACCOUNTCODE = '331'
GROUP BY CL2ACCOUNTCODE, PARNAME1, PARNAME2
ORDER BY CL2ACCOUNTCODE ASC
'#
## CREATE MIS CREDENTIALS ##
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection("Connection Timeout=0")
$SqlConnection.ConnectionString = "Data Source=$MISA;Initial Catalog=$DB;
Initial Catalog=$DB;User ID=$userName;Password=$PassWord;"
## - Runs Script from Set Location
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
$SqlCmd.CommandTimeout=$timeout;
$SqlCMD.CommandText = $CL2CashPositionsScript;
$SqlCmd.Connection = $SqlConnection;
## - Extract Data and build sql data object
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
$SqlAdapter.SelectCommand = $SqlCmd;
$DataSet = New-Object System.Data.DataSet;
$SqlAdapter.Fill($DataSet);
$DataSetTable = $DataSet.Tables["Table"];
#######
$CL2Location = 'L:\Controls\BROKER CASH RECONCILIATIONS\cl2cashpositions-331-Correctedb.csv'
$dbnameone = "brokerreconciliation"
[System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$mysqlConn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection
$mysqlConn.ConnectionString = "SERVER=localhost;DATABASE=brokerreconciliation;UID=root;PWD=''"
$mysqlConn.Open()
$ccmd = New-Object MySql.Data.MySqlClient.MySqlCommand
$ccmd.Connection = $mysqlConn
$ccmd.CommandText = "DROP DATABASE IF EXISTS " + $dbnameone
$ccmd.ExecuteNonQuery()
$ccmd.CommandText = 'CREATE SCHEMA `' + $dbnameone + '`'
$ccmd.ExecuteNonQuery()
$dbonetablescript = #"
CREATE TABLE brokerreconciliation.CL2 (
`ID` MEDIUMINT(8) unsigned NOT NULL auto_increment,
`CL2ACCOUNTCODE` char(12) default NULL,
`CBALANCE` char(20) default NULL,
`PARNAME1` varchar(30) default NULL,
PRIMARY KEY (`ID`)
) AUTO_INCREMENT=1;
"#
$ccmd.CommandText = $dbonetablescript
$ccmd.ExecuteNonQuery()
$ccmd = New-Object MySql.Data.MySqlClient.MySqlCommand
$ccmd.Connection = $mysqlConn
$ccmd.CommandText = "truncate table " + $dbnameone + ".CL2;"
$ccmd.ExecuteNonQuery()
foreach ($i in $DataSetTable) {
$ccmd.CommandText =
"INSERT INTO customers (cl2accountcode,cbalance,parname1) VALUES ("
+$i.cl2accountcode+"';'"+$i.cbalance+"';'"+$i.parname+"');"
$ccmd.ExecuteNonQuery()
}
$mysqlConn.Close()

You can't wrap strings like this:
$ccmd.CommandText =
"INSERT INTO customers (cl2accountcode,cbalance,parname1) VALUES ("
+$i.cl2accountcode+"';'"+$i.cbalance+"';'"+$i.parname+"');"
PowerShell will interpret
$ccmd.CommandText =
"INSERT INTO customers (cl2accountcode,cbalance,parname1) VALUES ("
and
+$i.cl2accountcode+"';'"+$i.cbalance+"';'"+$i.parname+"');"
as separate statements, because the first two lines are a complete statement in and by themselves. The third line then throws an error, because +$i.cl2accountcode (i.e. $null + [int]) becomes an integer, and [int] + [string] is only valid if the string can be cast to an integer (which is not the case for the string ';').
To make string concatenation work across lines you need to either escape the line break
$ccmd.CommandText =
"INSERT INTO customers (cl2accountcode,cbalance,parname1) VALUES (" `
+$i.cl2accountcode+"';'"+$i.cbalance+"';'"+$i.parname+"');"
or put the concatenation operator at the end of the line (so PowerShell knows there is more to come)
$ccmd.CommandText =
"INSERT INTO customers (cl2accountcode,cbalance,parname1) VALUES (" +
$i.cl2accountcode+"';'"+$i.cbalance+"';'"+$i.parname+"');"

Related

SSRS Download All History Snapshots

Is it possible to download all the history snapshots of a report at once? Preferably as a CSV. Would save a lot time instead of clicking into each one individually and selecting save as CSV.
I only see the option to Delete
In PowerShell, you can loop through each snapshot and save them using this example:
<#
Description: Save SSRS Report Snapshots
#>
$sql = "
DECLARE #ReportName NVARCHAR(200) = 'Your Report Name'; --change to NULL for every snapshot
DECLARE #FileFormat NVARCHAR(50) = 'CSV'; --HTML5,PPTX,ATOM,HTML4.0,MHTML,IMAGE,EXCEL (for .xls),EXCELOPENXML (for .xlsx),WORD (for .doc),WORDOPENXML (for .docx),CSV,PDF,XML
DECLARE #FileExtn NVARCHAR(50) = 'csv';
DECLARE #ServerName NVARCHAR(100) = 'http://YourServerName';
DECLARE #DateFrom DATE = CAST(DATEADD(DAY, -1, GETDATE()) AS DATE); --change to NULL for every snapshot
DECLARE #ExportPath NVARCHAR(200) = 'C:\Temp\';
SELECT
--[ReportID] = [c].[itemid]
-- , [ReportName] = [c].[name]
-- , [ReportPath] = [c].[path]
-- , [SnaphsotDate] = FORMAT([h].[snapshotdate], 'dd-MMM-yyyy')
-- , [SnapshotDescription] = [s].[DESCRIPTION]
-- , [SnapshotEffectiveParams] = [s].[effectiveparams]
-- , [SnapshotQueryParams] = [s].[queryparams]
-- , [ScheduleName] = [sc].[name]
-- , [ScheduleNextRunTime] = CONVERT(VARCHAR(20), [sc].[nextruntime], 113)
[ExportFileName] = #ExportPath + REPLACE([c].[name], ' ', '_') + '_' + FORMAT([h].[snapshotdate], 'yyyyMMdd_HHmm') + '.' + #FileExtn
, [SnapshotUrl] =
#ServerName
+ '/ReportServer/Pages/ReportViewer.aspx?'
+ [c].[path] + '&rs:Command=Render&rs:Format='
+ #FileFormat + '&rs:Snapshot='
+ FORMAT([h].[snapshotdate], 'yyyy-MM-ddTHH:mm:ss')
FROM
[ReportServer].[dbo].[History] AS [h] WITH(NOLOCK)
INNER JOIN [ReportServer].[dbo].[SnapshotData] AS [s] WITH(NOLOCK) ON [h].[snapshotdataid] = [s].[snapshotdataid]
INNER JOIN [ReportServer].[dbo].[Catalog] AS [c] WITH(NOLOCK) ON [c].[itemid] = [h].[reportid]
INNER JOIN [ReportServer].[dbo].[ReportSchedule] AS [rs] WITH(NOLOCK) ON [rs].[reportid] = [h].[reportid]
INNER JOIN [ReportServer].[dbo].[Schedule] AS [sc] WITH(NOLOCK) ON [sc].[scheduleid] = [rs].[scheduleid]
WHERE
1=1
AND [rs].[reportaction] = 2
AND (#ReportName IS NULL OR [c].[Name] = #ReportName)
AND (#DateFrom IS NULL OR [h].[snapshotdate] >= CAST(DATEADD(DAY, -1, GETDATE()) AS DATE))
ORDER BY
[c].[name]
, [h].[snapshotdate];
;"
$server = 'YourServerName';
$dbs = 'MASTER';
$dsn = "Data Source=$server; Initial Catalog=$dbs; Integrated Security=SSPI;";
$cn = New-Object System.Data.SqlClient.SqlConnection($dsn);
#execute merge statement here with parameters
$cn = New-Object System.Data.SqlClient.SqlConnection($dsn);
$cn.Open();
$cmd = $cn.CreateCommand();
$cmd.CommandText = $sql
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $cmd
$cmd.Connection = $cn
$ds = New-Object System.Data.DataSet
$SqlAdapter.Fill($ds)
$cn.Close()
$Result = $ds.Tables[0]
Foreach ($item in $Result)
{
#Write-Host $item.name
$SnapshotUrl = $item.SnapshotUrl
$ExportFileName = $item.ExportFileName
(Invoke-WebRequest -Uri $SnapshotUrl -OutFile $ExportFileName -UseDefaultCredentials -TimeoutSec 240);
}
https://learn.microsoft.com/en-us/sql/reporting-services/url-access-parameter-reference?view=sql-server-ver15
Was having trouble with powershell, so thought I'd post simplified version of my rough Python solution inspired by the resource from #aduguid's answer.
import requests
from requests_negotiate_sspi import HttpNegotiateAuth
import os
def downloadFile(url, file_name, download_folder, session):
response = session.get(url, stream=True) # open the download link
file_path = os.path.join(download_folder, file_name)
with open(file_path, 'wb') as file: # create a new file with write binary mode
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
# Can also use '/Reports()' for non-linked reports.
# Can also pass in 'path="<report_path>"' instead of using id numbers,
# e.g. '.../Reports(path="/cool%20reports/my%20report")/HistorySnapshots'
api_url = r'http://<server_name>/reports/api/v2.0/LinkedReports(<item_id>)/HistorySnapshots'
session = requests.session()
session.auth = HttpNegotiateAuth() # uses windows log in
response = session.get(api_url)
hs_snapshot_list = response.json()['value']
for item_dict in hs_snapshot_list:
download_url = (r'http://<server_name>/ReportServer/Pages/ReportViewer.aspx?<report_path>'
+ '&rs:Snapshot=' + item_dict['HistoryId']
+ '&rs:Format=CSV')
downloadFile(download_url, '<your_file_name>', '<your_download_folder>', session)
SSRS API Resource:
https://app.swaggerhub.com/apis/microsoft-rs/SSRS/2.0#/Reports/GetReportHistorySnapshots

Can't return the last known ID after an INSERT statement

I am trying to return the last inserted ID after running a MySQL INSERT statement with PowerShell. My INSERT works fine and the data is inserted into the database as expected. The issue I am having is grabbing the ID of that row that was just inserted.
My Code is below:
./MySQL.ps1 -Query "insert into table (field1,field2,field3,field4) values ('$val1','$val2','$val3','$val4')"
$last_id = ./MySQL.ps1 -Query "SELECT LAST_INSERT_ID()"
Write-Host "Last ID: $last_id"
returns:
Last ID: System.Data.DataRow
MySQL.ps1:
Param(
[Parameter(
Mandatory = $true,
ParameterSetName = '',
ValueFromPipeline = $true)]
[string]$Query
)
$MySQLAdminUserName = 'root'
$MySQLAdminPassword = 'password'
$MySQLDatabase = 'storage_manager'
$MySQLHost = 'localhost'
$ConnectionString = "server=" + $MySQLHost + ";port=3306;uid=" +
$MySQLAdminUserName + ";pwd=" + $MySQLAdminPassword +
";database=" + $MySQLDatabase
try {
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$Connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$Connection.ConnectionString = $ConnectionString
$Connection.Open()
$Command = New-Object MySql.Data.MySqlClient.MySqlCommand($Query, $Connection)
$DataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($Command)
$DataSet = New-Object System.Data.DataSet
$RecordCount = $dataAdapter.Fill($dataSet, "data")
$DataSet.Tables[0]
} catch {
Write-Host "ERROR : Unable to run query : $query `n$Error[0]"
} finally {
$Connection.Close()
}
I have also tried with the following and get the same info.
SELECT max(id) FROM mytab WHERE category = 1
Your function returns a DataTable object, not just a value. To get the value you need to select it via the field name (in your case the name of the SQL function):
$result = ./MySQL.ps1 -Query "SELECT LAST_INSERT_ID()"
$last_id = $result.'LAST_INSERT_ID()'
Write-Host "Last ID: $last_id"
The quotes around LAST_INSERT_CD() in the second line are required, because the name of the property includes parentheses, and without quotes PowerShell would interpret LAST_INSERT_ID() as a method instead of a property. You can avoid the quotes by specifying an alias without parentheses (or other special characters):
$result = ./MySQL.ps1 -Query "SELECT LAST_INSERT_ID() AS foo"
$last_id = $result.foo
Write-Host "Last ID: $last_id"

Csv upload to mysql in perl

I am new in perl programming language. Can you please guide how to write csv upload into mysql database.
I have following table & csv file format
Create Table:
CREATE TABLE consumeruser (
ConsumerId int(10) NOT NULL AUTO_INCREMENT,
ConsumerName varchar(45) DEFAULT NULL,
ConsumerMobNo varchar(10) DEFAULT NULL,
PRIMARY KEY (ConsumerId)
) ENGINE=InnoDB AUTO_INCREMENT=4494 DEFAULT CHARSET=latin1
Csv file example:
4495,Sanchita Mehra,999999999
4496,Rupesh Shewalkar,88888888
4497,Aditya Mishra,111111111
Csv upload should be on basis of mobile number, suppose if table already contain mobile 111111111 Then that row should be skip. Means all mobile numbers should be check with existing data, if it is already in database that row should not be insert in database & rest of inserted into database.
You can check for the count of the row to see if the data is already present and then continue to next statement if its present. The implementation is for SQLite and you can change it to MySQL.
#!/usr/bin/perl
use Modern::Perl '2012';
use DBD::SQLite;
use warnings;
my $dbh = DBI->connect("dbi:SQLite:dbname=Consumer");
while(<DATA>){
chomp;
my ($id, $name, $MobNo) = split /,/;
my $query = "select count(*) from consumeruser where ConsumerMobNo = ?";
my $sth = $dbh->prepare($query);
$sth->execute($MobNo);
my $row = $sth->fetch();
next if(#$row > 0);
my $insertStatement = "insert into consumeruser values(?,'?',?)";
$sth = $dbh->prepare($insertStatement);
$sth->execute($id,$name,$MobNo);
}
__DATA__
4495,Sanchita Mehra,999999999
4496,Rupesh Shewalkar,88888888
4497,Aditya Mishra,111111111
4498,Aditya,111111111
Edit:
For fetching all the mobile numbers in the array. You can do like this.
my #MobileNumbers;
my $mobileNumberQuery = "select ConsumerMobNo from consumeruser";
my $sth = $dbh->prepare($mobileNumberQuery);
$sth->execute();
while(my $row = $sth->fetch()){
push #MobileNumbers, #$row;
}
Please refer to perldoc DBI for various ways of accessing the results.

register data from erlang to table mysql

I have a table in mysql named person
this a simple code of insertion of data in the table person
$id = "1";
$firstname = "afif";
$lastname = "kaled";
$test = mysql_connect("localhost", "root", "root");
if ($test) {
mysql_select_db("basetest", $test);
}
$sql = " INSERT INTO `person` SET
`id` = '" . $id . "',
`firstname` = '" . $firstname . "',
`lastname` = '" . $lastname . "' ";
#mysql_query($sql, $test);
I want to modify this function
test()->
Id ="11",
Firstname ="afif",
Lastname ="kaled",
%% here I want to register this data in the table person .
so the table person will have this data
11 afif kaled
I want to know if is it possible to register data from erlang to table mysql
I have already done an example of transfer data from erlang to txt file with this code :
exporttxt()->
F = fun() -> mnesia:foldl(fun(X,Acc) -> [X|Acc] end, [],person) end,
{atomic,L} = mnesia:transaction(F),
file:write_file("test.txt",[io_lib:format("~p\t~p\t~p~n",[F1,F2,F3]) ||
#person{id = F1,firstname = F2,lastname = F3} <- L]).
but now as I already said I want to know is it possible or not to send data from erlang to a table in mysql
Of course it is possible.
Try to use a search before asking questions.

Problem with DBD and mysql in perl

Please I am having problem tracking down the problem with this code I have been trying for hours . it gives me the error DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at line 15
sub Split_Into_Words
{
#### Connection parameters ############################
my $dsn = "dbi:mysql:malware:localhost:3306";
my $user = 'root';
my $passwd = 'sxxxs';
########################################################
my $domain ;
my $countDir = 0 ;
my $file = shift ;
my $labelID = (split(/[.]/ , $file))[1] ; ### Split and get the middle value since format is temporay.
#### Query String ############################################################################
my $InsertIntoHostTable_QS = "INSERT INTO TB_host(HostName , UrlID , ExtID) Values (? , ? , ? ) ; ";
my $InsertIntoDomainTable_QS = "INSERT IGNORE INTO TB_Domain(Domain) values (?) ;" ;
my $InsertIntoArgVal_QS = "INSERT INTO TB_Arg_Value(Arg, URL_ID) VALUES (? , ? ) ; " ;
my $InsertIntoDirectory_QS = "INSERT INTO TB_Directory(DIRNAME , DEPTH , URLID) VALUES (? , ? , ? )" ;
my $InsertIntoExtension_QS = "INSERT IGNORE INTO TB_Extension (Extension) values ( ? ) ; ";
my $InsertIntoExtensionNULL_QS = "INSERT IGNORE INTO TB_Extension (ID , Extension) values (? , ? ) ; ";
my $SelectString = " Select URL , ID from TB_URL where LabelID = '" . $labelID."';";
my $InsertIntoFileName_QS = "INSERT IGNORE INTO TB_FileName( filename) VALUES (?) ; " ;
###################################################################################################
my $DBIConnect = DBI->connect($dsn , $user , $passwd) or die("Cannot connect to datadbase $DBI::errstr\n");
print ("Splitting Into Words \n");
######Initialization of a default DB value #################
my $sth = $DBIConnect->prepare( $InsertIntoExtensionNULL_QS);
$sth->execute(1 , 'null') or die("Error Executing the Insertion" . $sth->errstr );
$sth->finish();
#############################################################
$sth = $DBIConnect ->prepare($SelectString);
sleep(10);
open (FH , '<' , $file); # Open file to be read from disk
my $i = 0;
$sth->execute() or die("Error Executing the Insertion" . $sth->errstr );
->line 15 while(my $hash_ref = $sth->fetchrow_hashref )
{
my $extensionID = "1";
my $intialURL = $hash_ref->{URL} ;
my $initialID = $hash_ref->{ID};
}
}
I'm not sure if this is the issue, but you may not need the finish after the insert. From the DBI doc:
Indicate that no more data will be fetched from this statement handle
before it is either executed again or destroyed. You almost certainly
do not need to call this method.
Adding calls to finish after loop that fetches all rows is a common
mistake, don't do it, it can mask genuine problems like uncaught fetch
errors.
If that is the problem, you may want to create a second statement handler for the select call.
Apart from the annoyingly long SQL variable names, $SelectString should contain a "?", in case $labelID contains something that could break the query or cause an injection.
prepare() doesn't absolutely require a "?", but if execute has parameters, then there must be a matching number of "?" in the query string.
First $sth->finish() is not needed because the query is an insert and doesn't return any rows.
Second 'die' should be "Error executing query", because it executing $SelectString
Note SQL convention is to write all in uppercase, and for extra safety enclose field names in backticks. Queries do not end with semicolon. Also note that "my" variables are local to that between braces, { } so that my variables in the while loop will be unavailable afterwards.
Suggest formatting thus:
sub Split_Into_Words {
#### Connection parameters ############################
my $dsn = "dbi:mysql:malware:localhost:3306";
my $user = 'root';
my $passwd = 'sxxxs';
########################################################
my $domain ;
my $countDir = 0 ;
my $file = shift ;
my $labelID = (split(/[.]/ , $file))[1] ; ### Split and get the middle value since format is temporary.
#### Query String ############################################################################
my $InsertIntoHostTable_QS = "INSERT INTO `TB_host` (`HostName`,`UrlID`,`ExtID`) VALUES (?,?,?)";
my $InsertIntoDomainTable_QS = "INSERT IGNORE INTO `TB_Domain` (`Domain`) VALUES (?)";
my $InsertIntoArgVal_QS = "INSERT INTO `TB_Arg_Value` (`Arg`,`URL_ID`) VALUES (?,?)";.
my $InsertIntoDirectory_QS = "INSERT INTO `TB_Directory` (`DIRNAME`,`DEPTH`,`URLID`) VALUES (?,?,?)";
my $InsertIntoExtension_QS = "INSERT IGNORE INTO `TB_Extension` (`Extension`) VALUES (?)";
my $InsertIntoExtensionNULL_QS= "INSERT IGNORE INTO `TB_Extension` (`ID`,`Extension`) VALUES (?,?)";
my $SelectString = "SELECT `URL`,`ID` FROM `TB_URL` WHERE `LabelID`=?";
my $InsertIntoFileName_QS = "INSERT IGNORE INTO `TB_FileName` (`filename`) VALUES (?)";
###################################################################################################
my $DBIConnect = DBI->connect($dsn , $user , $passwd) or die("Cannot connect to datadbase $DBI::errstr\n");
print ("Splitting Into Words \n");
######Initialization of a default DB value #################
my $sth = $DBIConnect->prepare( $InsertIntoExtensionNULL_QS);
$sth->execute(1 , 'null') or die("Error executing the Insertion: " . $sth->errstr );
# $sth->finish(); # not needed because it's an insert
#############################################################
$sth = $DBIConnect->prepare($SelectString);
sleep(10);
open (FH , "<$file"); # Open file to be read from disk
my $i = 0;
$sth->execute($labelID) or die("Error executing query: " . $sth->errstr );
while(my $hash_ref = $sth->fetchrow_hashref ) {
my $extensionID = "1";
my $intialURL = $hash_ref->{URL};
my $initialID = $hash_ref->{ID};
}