What kind of newline character is in my multiline string literal? - swift

I'm trying to replace a new line with something, or remove it, but I can't even figure out what kind of new line character it is. I've tried \n and \r as a regular expression:
var testStr =
"""
.db $82, $14, $2c, $62, $26, $10, $28, $80, $04
.db $82, $14, $2c, $62, $26, $10, $28, $80, $04
.db $82, $08, $1e, $5e, $18, $60, $1a, $80, $04
.db $82, $08, $1e, $5e, $18, $60, $1a, $86, $04
.db $83, $1a, $18, $16, $84, $14, $1a, $18, $0e, $0c
.db $16, $83, $14, $20, $1e, $1c, $28, $26, $87
.db $24, $1a, $12, $10, $62, $0e, $80, $04, $04
.db $00
"""
testStr = testStr.replacingOccurrences(of: "^\\r*", with: "!", options: .regularExpression)
testStr = testStr.replacingOccurrences(of: "^\\n*", with: "!", options: .regularExpression)
print(testStr) // does not replace new lines

Looks like you've made the RegEx a little more complicated than it needs to be. As mentioned in the comments, you can remove the beginning anchor ^ and the *. The newline characters the multiline literals creates are caught by \n
Also, remember that your indentation matters with multiline string literals. You want the ending """ to be at the level at which the text is indented.
var testStr =
"""
.db $82, $14, $2c, $62, $26, $10, $28, $80, $04
.db $82, $14, $2c, $62, $26, $10, $28, $80, $04
.db $82, $08, $1e, $5e, $18, $60, $1a, $80, $04
.db $82, $08, $1e, $5e, $18, $60, $1a, $86, $04
.db $83, $1a, $18, $16, $84, $14, $1a, $18, $0e, $0c
.db $16, $83, $14, $20, $1e, $1c, $28, $26, $87
.db $24, $1a, $12, $10, $62, $0e, $80, $04, $04
.db $00
"""
testStr = testStr.replacingOccurrences(of: "\\n", with: "!", options: .regularExpression)
print(testStr)
Yields:
.db $82, $14, $2c, $62, $26, $10, $28, $80, $04!.db $82, $14, $2c, $62, $26, $10, $28, $80, $04!.db $82, $08, $1e, $5e, $18, $60, $1a, $80, $04!.db $82, $08, $1e, $5e, $18, $60, $1a, $86, $04!.db $83, $1a, $18, $16, $84, $14, $1a, $18, $0e, $0c!.db $16, $83, $14, $20, $1e, $1c, $28, $26, $87!.db $24, $1a, $12, $10, $62, $0e, $80, $04, $04!.db $00

Related

Why postgres query can't recognize string type in #Query string?

I am using Spring JPA repositories with PostgreSQL datasource. Here is the problematic query which causes the error:
#Query("select ir from table ir " +
" join table1 dc on ir.ds.id = dc.id " +
"join table2 p on dc.prj.id = p.id " +
"join table3 pc on p.id = pc.prj.id " +
"where (:int1 is null or p.id = :int1) " +
" and (:int2 is null or dc.id = :int2) " +
"and (:str3 is null or concat(pc.id, '_', pc.cl) = :str3)")
List<EntityIR> findAllBy(#Param("int1") Integer int1,
#Param("int2") Integer int2,
#Param("str3") String str3);
When I'm passing the value 3_it100 into str3 parameter I'm getting the following error:
Caused by: org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $5
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553) ~[postgresql-42.2.16.jar:42.2.16]
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285) ~[postgresql-42.2.16.jar:42.2.16]
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323) ~[postgresql-42.2.16.jar:42.2.16]
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473) ~[postgresql-42.2.16.jar:42.2.16]
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393) ~[postgresql-42.2.16.jar:42.2.16]
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164) ~[postgresql-42.2.16.jar:42.2.16]
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:114) ~[postgresql-42.2.16.jar:42.2.16]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-3.4.5.jar:?]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.5.jar:?]
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.getResultSet(Loader.java:2341) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2094) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2056) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:953) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:350) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2887) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.doList(Loader.java:2869) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2701) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.Loader.list(Loader.java:2696) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1415) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1565) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1533) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.hibernate.query.Query.getResultList(Query.java:165) ~[hibernate-core-5.4.20.Final.jar:5.4.20.Final]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:126) ~[spring-data-jpa-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88) ~[spring-data-jpa-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:154) ~[spring-data-jpa-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:142) ~[spring-data-jpa-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.3.3.RELEASE.jar:2.3.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367) ~[spring-tx-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.8.RELEASE.jar:5.2.8.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.8.RELEASE.jar:5.2.8.RELEASE]
... 112 more
How do I specify explicitly in a query what is the type of str3 parameter?
The problem is probably that you supplied a NULL value for str3, and NULL can be any data type, so the database cannot guess what you mean.
Try to be explicit:
"and (CAST (:str3 AS text) is null or concat(pc.id, '_', pc.cl) = CAST (:str3 AS text))"

Array in Tuple.of (vert.x pgclient)

this is my postgresql CTE's. Works well with various examples.
with vtas_itms as (
insert into ventas (idafip, tipo_venta, nrodoc_persona, tperso_persona, nrodoc_vendedor,
tperso_vendedor, idfinanciacion, cancuotas, fecha_comprobante, punto_venta,
numero_comprobante, cae, fecha_vtocae, situacion_fiscal, nombre_cliente,
numero_remito, coeficiente, bonificacion, obs_generales, obs_comerciales,
obs_afip, estado)
values (6, 'Efectivo', 17412018, 'Cliente', 14808837,
'Vendedor', 1, null, '2020-10-27', 6,
215, '70332083246226', '2020-11-02', 'Consumidor Final', 'Consumidor Final',
null, null, null, null, null,
null, 'Pagada')
returning idventa
)
insert into ventas_items (idventa, idarticulo, cantidad, precio_unitario, descuento_articulo, saldo_articulo)
select vtas_itms.idventa, d1.col1, d1.col2, d1.col3::numeric, d1.col4::numeric, d1.col5::numeric
from vtas_itms
cross join (values (3,2,82.38,null,null), (4,1,43.12,null,null),(1,0.750,286.30,null,null)) as d1(col1,col2,col3,col4,col5)
Pay attention to cross join values: 5 columns with "n" occurrences...it's an array, of course.
Now, on the server side (business):
private static final String INSERT_VENTA = "with vtas_itms as ("
+ "insert into ventas (idafip, tipo_venta, nrodoc_persona, tperso_persona, nrodoc_vendedor, tperso_vendedor, idfinanciacion, cancuotas, fecha_comprobante, punto_venta, "
+ "numero_comprobante, cae, fecha_vtocae, situacion_fiscal, nombre_cliente, numero_remito, coeficiente, bonificacion, obs_generales, obs_comerciales, "
+ "obs_afip, estado) "
+ "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22) "
+ "returning idventa) "
+ "insert into ventas_items (idventa, idarticulo, cantidad, precio_unitario, descuento_articulo, saldo_articulo) "
+ "select vtas_itms.idventa, d1.col1, d1.col2, d1.col3::numeric, d1.col4::numeric, d1.col5::numeric "
+ "from vtas_itms "
+ "cross join ($23::text[]) as d1(col1,col2,col3,col4,col5)";
Look at the $23::text[] parameter...I need to put in the prepared query (after "venta.getEstado()") and in the API...and I don't known how
public void putVenta(RoutingContext routingContext) {
Venta venta = Json.decodeValue(routingContext.getBodyAsString(), Venta.class);
HttpServerResponse response = routingContext.response();
pgClient
.preparedQuery(INSERT_VENTA)
.execute(Tuple.of(venta.getIdafip(), venta.getTventa(), venta.getNrodoc_persona(), venta.getTperso_persona(), venta.getNrodoc_vendedor(), venta.getTperso_vendedor(),
venta.getIdfinanciacion(), venta.getCancuotas(), venta.getFecha_comprobante(), venta.getPunto_venta(), venta.getNumero_comprobante(), venta.getCae(),
venta.getFecha_vtocae(), venta.getSituacion_fiscal(), venta.getNombre_cliente(), venta.getNumero_remito(), venta.getCoeficiente(), venta.getBonificacion(),
venta.getObs_generales(), venta.getObs_comerciales(), venta.getObs_afip(), venta.getEstado()), ar -> {
if (ar.succeeded()) {
response.putHeader("content-type", "application/json; charset=utf-8")
.setStatusCode(201)
.end();
} else {
System.out.println("Failure: " + ar.cause().getMessage());
response.putHeader("content-type", "application/json; charset=utf-8")
.end(Json.encodePrettily(ar.cause().getMessage()));
}
});
}
´´´
API (routes). After parameter /:estado)
// tag::createRoutes[]
router.put("/api/ventas/insertVenta/:idafip/:tipo_venta/:nrodoc_persona/:tperso_persona/:nrodoc_vendedor/:tperso_vendedor/:idfinanciacion"
+ "/:cancuotas/:fecha_comprobante/:punto_venta/:numero_comprobante/:cae/:fecha_vtocae/:situacion_fiscal/:nombre_cliente"
+ "/:nro_remito/:coeficiente/:bonificacion/:obs_generales/:obs_comerciales/:obs_afip/:estado").handler(bizVentas::putVenta);
Any help?. TIA
Ernesto
You're looking to create a virtual table from a single string.
That's actually possible with Postres.
You can provide your string in an array syntax, using {}, and then use unnest to split every string into a separate row.
Then you use string_to_array to split every row into separate columns.
select a[1], a[2], a[3], a[4], a[5]
from (
select string_to_array(nest.l, ',') as a
from (
select unnest('{"3,2,82.38,null,null","4,1,43.12,null,null"}'::text[]) as l
) nest) b
You can replace your values () part now with this query.
From Vert.x side, you'll have to create exactly this string, and bind it.

Need Help in Perl looping

I have a file with following data. I want to print in an external file with sum of every 9 rows. Here is my data.
file.xyz
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
My output looks like
-2.121332105 -5.405270886 -2.234333276 6.221675693
-2.121332105 -5.405270886 -2.234333276 6.221675693
Where the first line is sum of 1-9 and second line is sum from 10-18. Here data are same for first 9 and last 9 rows, it gives same value. I want to print sum of EVERY NINE lines of big files with thousands line file.
Here is my code, it calculates the total sum, but I need to split into two parts as above.
Thank you for your help and appreciated.
my #sums;
open FILE, "file.xyz" or die "Can't find";
while( <FILE> ) { # there is FILE written within angular brackets
my #summands = split / /;
foreach my $i ( 0 .. $#summands ) {
$sums[$i] += $summands[$i];
}
}
$total = sqrt($sums[0]*$sums[0]+$sums[1]*$sums[1]+$sums[2]*$sums[2]);
print "$sums[0], $sums[1], $sums[2], $total\n";
Something like the following:
use strict;
use warnings;
use autodie;
open my $fh, '<', 'file.xyz';
my #sums;
my $n = 0;
while (<$fh>) {
my #summands = split /\s+/;
foreach my $i ( 0 .. $#summands ) {
$sums[$i] += $summands[$i];
}
unless ( ++$n % 9 ) {
my $total = sqrt( $sums[0] * $sums[0] + $sums[1] * $sums[1] + $sums[2] * $sums[2] );
print "$sums[0], $sums[1], $sums[2], $total\n";
#sums = ();
}
}
Add a line counter and move the $total and print code into the loop under a conditional. You'll also need to clear the sums there.
if ($lines % 9 == 0) {
...
}
Use Input line number, $., to determine when your on every 9th line:
use strict;
use warnings;
use autodie;
use List::Util qw(sum);
#open my $fh, '<', "file.xyz";
my $fh = \*DATA;
my #sums;
while (<$fh>) {
my #cols = split ' ';
for my $i ( 0 .. $#cols ) {
$sums[$i] += $cols[$i];
}
if ( ( $. % 9 ) == 0 or eof ) {
my $weighted_total = sqrt sum map $_**2, #sums;
print join( ', ', #sums, $weighted_total ), "\n";
#sums = ();
}
}
warn "FH did not end an on even multiple of 9" if $. % 9;
__DATA__
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
-0.485718003092488 3.25568455554021 -0.60544991716881
-1.01253068155602 -2.49251542491767 0.713923699625837
0.791137982988487 -2.56492609246597 -0.853251541212567
Outputs:
-2.12133210498006, -5.40527088553029, -2.23433327626662, 6.22167569349391
-2.12133210498006, -5.40527088553029, -2.23433327626662, 6.22167569349391
The whole thing in Perl-golf style, watered down with a bit of whitespace and indentation:
while (<>) {
#l = split;
#s = map { $s[$_] + $l[$_] } 0..$#l;
next if ++$n % 9;
$, = ' ';
print #s, sqrt(eval join '+', (map { $_*$_ } #s)), "\n";
#s = ();
}
And some real Perl-golf, inspired by #Nemo, but even shorter:
perl -lanE '$s[$_]+=$F[$_]for 0..$#F;$.%9&&next;print"#s #{[sqrt eval join qq(+),map $_**2,#s]}";#s=()'
Finding the used tricks is left as an exercise to the readers. :-)

Extracting value from a xml file using awk

I have a text stream like this
<device nid="05023CA70900" id="1" fblock="-1" type="switch" name="Appliance Home" brand="Google" active="false" energy_lo="427" />
<device nid="0501C1D82300" id="2" fblock="-1" type="switch" name="TELEVISION Home" brand="Google" active="pending" energy_lo="3272" />
from which i would like an output like
05023CA70900##1##-1##switch##Appliance Home##Google##false##427
0501C1D82300##2##-1##switch##TELEVISION Home##Google##pending##3272
There are many lines in the input all of which are not writable.
How can we achieve this using awk or sed ?
Following awk should work:
awk -F '"' '$1 == "<device nid=" { printf("%s##%s##%s##%s##%s##%s##%s##%s\n",
$2, $4, $6, $8, $10, $12, $14, $16)}' file
PS: It is not always best approach to parse XML using awk/sed.
Its very simple in perl . So why not use perl ?
perl -lne 'push #a,/\"([\S]*)\"/g;print join "##",#a;undef #a' your_file
Sample tested:
> cat temp
<device nid="05023CA70900" id="1" fblock="-1" type="switch" name="Appliance Home" brand="Google" active="false" energy_lo="427" />
<device nid="0501C1D82300" id="2" fblock="-1" type="switch" name="TELEVISION Home" brand="Google" active="pending" energy_lo="3272" />
> perl -lne 'push #a,/\"([\S]*)\"/g;print join "##",#a;undef #a' temp
05023CA70900##1##-1##switch##Google##false##427
0501C1D82300##2##-1##switch##Google##pending##3272
>
awk -F\" -v OFS="##" '/^<device nid=/ { print $2, $4, $6, $8, $10, $12, $14, $16 }' file
or more generally:
awk -F\" '/^<device nid=/ {for (i=2;i<=NF;i+=2) printf "%s%s",(i==2?"":"##"),$i; print ""}' file
To address your question in your comment: If you could have a tab in front of <device nid:
awk -F\" '/^\t?<device nid=// ...'
If you meant something else, update your question and provide more representative input.

Why can't I insert HTML into my database?

I have errors when inserting into my database. I have tried everything to sus this. Someone mentioned usind DBI's trace() to track what is going wrong but i cannot make heads or tails of what is going on. Could someone please take a look and see what they think might be the problem.
D
BI 1.607-ithread default trace level set to 0x0/1 (pid 13524) at cgitest.pl line 10
-> DBI->connect(*****************************************************)
-> DBI->install_driver(mysql) for MSWin32 perl=5.010001 pid=13524 ruid=0 euid=0
install_driver: DBD::mysql version 4.011 loaded from C:/Perl/site/lib/DBD/mysql.pm
<- install_driver= DBI::dr=HASH(0x37be1fc)
!! warn: 0 CLEARED by call to connect method
<- connect('database=web110-accounts;host=79.170.44.110;', 'web110-accounts', ...)= DBI::db=HASH(0x37bdc8c) at DBI.pm line 638
<- STORE('PrintError', 1)= 1 at DBI.pm line 690
<- STORE('AutoCommit', 1)= 1 at DBI.pm line 690
<- STORE('Username', 'web110-accounts')= 1 at DBI.pm line 693
<> FETCH('Username')= 'web110-accounts' ('Username' from cache) at DBI.pm line 693
<- connected(**********************************)= undef at DBI.pm line 699
<- connect= DBI::db=HASH(0x37bdc8c)
<- STORE('dbi_connect_closure', CODE(0x37c3634))= 1 at DBI.pm line 708
<- prepare('SELECT * FROM accounts WHERE KI = '9096699576bcc810df5bc311650c4ebd' ')= DBI::st=HASH(0x37bda24) at cgitest.pl line 61
<- execute= 1 at cgitest.pl line 62
<- rows= '1' at cgitest.pl line 63
<- fetchrow_hashref= HASH(0x37bd514)24keys row1 at cgitest.pl line 64
<- finish= 1 at cgitest.pl line 71
<- disconnect= 1 at cgitest.pl line 72
****************************************************************************
****************************************************************************
<- STORE('PrintError', 1)= 1 at DBI.pm line 690
<- STORE('AutoCommit', 1)= 1 at DBI.pm line 690
<- STORE('Username', 'web110-db-2')= 1 at DBI.pm line 693
<> FETCH('Username')= 'web110-db-2' ('Username' from cache) at DBI.pm line 693
<- connected('DBI:mysql:database=web110-db-2;host=79.170.44.110;', 'web110-db-2', ...)= undef at DBI.pm line 699
<- connect= DBI::db=HASH(0x3d615ac)
<- STORE('dbi_connect_closure', CODE(0x3d60f6c))= 1 at DBI.pm line 708
<- prepare('INSERT INTO ? ( headData, headDataOutput ) VALUES ( ?, ? )')= DBI::st=HASH(0x351659c) at cgitest.pl line 263
<- prepare('INSERT INTO ? ( bodyData, bodyDataOutput ) VALUES ( ?, ? )')= DBI::st=HASH(0x37bd914) at cgitest.pl line 264
<- prepare('INSERT INTO page_names (linkFromRoot, linkTrue, page_name, table_name, navigation, location) VALUES ( ?, ?, ?, ?, ?, ? )')= DBI::st=HASH(0x3d575fc) at cgitest.pl line 265
<- quote("http://www.themobilemakeover.co.uk/index.php")= "'http://www.themobilemakeover.co.uk/index.php'" at cgitest.pl line 271
<- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/index.php' ")= DBI::st=HASH(0x3d571bc) at cgitest.pl line 272
<- execute= '0E0' at cgitest.pl line 273
<- rows= '0' at cgitest.pl line 274
<- quote("The Mobile Makeover - Mobile Beautician")= "'The Mobile Makeover - Mobile Beautician'" at cgitest.pl line 289
<- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - Mobile Beautician' ")= DBI::st=HASH(0x3d56fdc) at cgitest.pl line 290
<- execute= '0E0' at cgitest.pl line 291
<- rows= '0' at cgitest.pl line 292
<- DESTROY(DBI::st=HASH(3d54254))= undef at cgitest.pl line 287
<- do('CREATE TABLE IF NOT EXISTS `6959bbd13fdb4df586a5b9d08aae1153_body` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`bodyData` TEXT NOT NULL,
`bodyDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 362
<- do('CREATE TABLE IF NOT EXISTS `6959bbd13fdb4df586a5b9d08aae1153_header` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`headData` TEXT NOT NULL,
`headDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 363
!! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''6959bbd13fdb4df586a5b9d08aae1153_header' ( headData, headDataOutput ) VALUES ( ' at line 1' (err#0)
<- execute('6959bbd13fdb4df586a5b9d08aae1153_header', '<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="The Mobile Makeover offers a wide range of services and treatments all from the luxuary of your own home!" />
<meta name="keywords" content="Mobile Makeover, Beauty Therapist, Beautician, Therapist, Mobile Therapist, Mansfield, Nottinghamshire" />
<meta name="language" content="en" />
<meta name="author" content="ACT Web Designs" />
<meta name="copyright" content="The Mobile Makeover" />
<meta name="publisher" content="ACT Web Designs" />
<meta name="country" content="United Kingdom" />
<meta name="city" content="Mansfield, Nottinghamshire" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta name="verify-v1" content="4lZIaMmjLMq+UA8nkPYB9RjF5RreNwF3Mzurm9JYvQM=" />
<title>The Mobile M...', ...)= undef at cgitest.pl line 365
!! ERROR: 1064 CLEARED by call to execute method
!! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''6959bbd13fdb4df586a5b9d08aae1153_body' ( bodyData, bodyDataOutput ) VALUES ( '<' at line 1' (err#0)
<- execute('6959bbd13fdb4df586a5b9d08aae1153_body', '<body>
<div id="wrapper">
<div id="header">
<div id="innerHeader">
<h1><span>The Mobile Makeover - Mobile Beauty Therapist - Mansfield Nottinghamshire</span></h1>
<div class="clear"></div>
<?php include("php/navigation.php"); ?>
<div class="clear"></div>
</div>
</div>
<div id="main">
<div id="content1" class="content vis">
<h2>Welcome to The Mobile Makeover</h2>
<div class="image1">
</div>
<p>Home visit appointments are designed to save you time and stress, by providing a service in the comfort of your own home, no need to worry about travel and traffic or facing the cold night air after a relaxing treatment.</p>
<p>If you have a baby or a toddler The Mobile Makeover can help you put together a package of treatments that is ada...', ...)= undef at cgitest.pl line 366
!! ERROR: 1064 CLEARED by call to execute method
<- execute("public_html/index.php", "http://www.themobilemakeover.co.uk/index.php", ...)= 1 at cgitest.pl line 367
<- DESTROY(DBI::st=HASH(3d56f5c))= undef at cgitest.pl line 270
<- quote("http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php")= "'http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php'" at cgitest.pl line 271
<- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php' ")= DBI::st=HASH(0x3d56d9c) at cgitest.pl line 272
<- execute= '0E0' at cgitest.pl line 273
<- rows= '0' at cgitest.pl line 274
<- quote("The Mobile Makeover - About Us")= "'The Mobile Makeover - About Us'" at cgitest.pl line 289
<- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - About Us' ")= DBI::st=HASH(0x3b07814) at cgitest.pl line 290
<- execute= '0E0' at cgitest.pl line 291
<- rows= '0' at cgitest.pl line 292
<- DESTROY(DBI::st=HASH(3d54254))= undef at cgitest.pl line 287
<- do('CREATE TABLE IF NOT EXISTS `30df18a64311aa9aaaa9576b030f0f83_body` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`bodyData` TEXT NOT NULL,
`bodyDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 362
<- do('CREATE TABLE IF NOT EXISTS `30df18a64311aa9aaaa9576b030f0f83_header` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`headData` TEXT NOT NULL,
`headDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 363
!! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''30df18a64311aa9aaaa9576b030f0f83_header' ( headData, headDataOutput ) VALUES ( ' at line 1' (err#0)
<- execute('30df18a64311aa9aaaa9576b030f0f83_header', '<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content=">My name is Kelly Knight, I am a highly Qualifed Mobile Beauty Therapist. I have trained in NVQ Level 2 and NVQ level 3 in Beauty Therapy with many additional courses and training..." />
<meta name="keywords" content="Mobile Makeover, About Us, Beauty Therapist, Mobile Therapist, Mansfield, Nottinghamshire" />
<meta name="language" content="en" />
<meta name="author" content="ACT Web Designs" />
<meta name="copyright" content="The Mobile Makeover" />
<meta name="publisher" content="ACT Web Designs" />
<meta name="country" content="United Kingdom" />
<meta name="city" content="Mansfield, Nottinghamshire" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>The Mobile Makeover - About U...', ...)= undef at cgitest.pl line 365
!! ERROR: 1064 CLEARED by call to execute method
!! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''30df18a64311aa9aaaa9576b030f0f83_body' ( bodyData, bodyDataOutput ) VALUES ( '<' at line 1' (err#0)
<- execute('30df18a64311aa9aaaa9576b030f0f83_body', '<body id="aboutUsPage">
<div id="wrapper">
<div id="header">
<div id="innerHeader">
<h1><span>The Mobile Makeover - About Us</span></h1>
<div class="clear"></div>
<?php include("php/navigation.php"); ?>
<div class="clear"></div>
</div>
</div>
<div id="main">
<div id="content1" class="content vis">
<h2>About Us - Kelly Night</h2>
<div class="image1">
</div>
<p>My name is Kelly Knight, I am a highly Qualified Mobile Beauty Therapist. I have trained in NVQ Level 2 and NVQ level 3 in Beauty Therapy with many additional courses and training gained within my time in the beauty industry. I have gained my years of experience from working at one of the UK's biggest Hotels & Spa chains where i worked as a salon supervisor. After being approached by a number of people to go mobile to their homes i recognised that the...', ...)= undef at cgitest.pl line 366
!! ERROR: 1064 CLEARED by call to execute method
<- execute("public_html/about-us-the-mobile-makeover.php", "http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php", ...)= 1 at cgitest.pl line 367
<- DESTROY(DBI::st=HASH(3d56f1c))= undef at cgitest.pl line 270
<- quote("http://www.themobilemakeover.co.uk/beauty-products-used.php")= "'http://www.themobilemakeover.co.uk/beauty-products-used.php'" at cgitest.pl line 271
<- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/beauty-products-used.php' ")= DBI::st=HASH(0x3d56f3c) at cgitest.pl line 272
<- execute= '0E0' at cgitest.pl line 273
<- rows= '0' at cgitest.pl line 274
<- quote("The Mobile Makeover - Beauty Products Used")= "'The Mobile Makeover - Beauty Products Used'" at cgitest.pl line 289
<- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - Beauty Products Used' ")= DBI::st=HASH(0x3d545a4) at cgitest.pl line 290
<- execute= '0E0' at cgitest.pl line 291
<- rows= '0' at cgitest.pl line 292
<- DESTROY(DBI::st=HASH(3d54684))= undef at cgitest.pl line 287
<- do('CREATE TABLE IF NOT EXISTS `02b5f135f611c1d7b0ec090182bc6cf5_body` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`bodyData` TEXT NOT NULL,
`bodyDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 362
<- do('CREATE TABLE IF NOT EXISTS `02b5f135f611c1d7b0ec090182bc6cf5_header` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`headData` TEXT NOT NULL,
`headDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 363
!! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''02b5f135f611c1d7b0ec090182bc6cf5_header' ( headData, headDataOutput ) VALUES ( ' at line 1' (err#0)
<- execute('02b5f135f611c1d7b0ec090182bc6cf5_header', '<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="We use a wide range of the finest products on the market today. Below is a short brief of just a few of the names which we believe give you the best results - we do not compromise when it comes to quality." />
<meta name="keywords" content="Mobile Makeover, Beauty Therapist, Beauty Products, Jessica, Calgel, Eve Taylor, Tantrick, Therapist, Mansfield, Nottinghamshire" />
<meta name="language" content="en" />
<meta name="author" content="ACT Web Designs" />
<meta name="copyright" content="The Mobile Makeover" />
<meta name="publisher" content="ACT Web Designs" />
<meta name="country" content="United Kingdom" />
<meta name="city" content="Mansfield, Nottinghamshire" />
<meta http-equiv="X-UA-Compa...', ...)= undef at cgitest.pl line 365
!! ERROR: 1064 CLEARED by call to execute method
!! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''02b5f135f611c1d7b0ec090182bc6cf5_body' ( bodyData, bodyDataOutput ) VALUES ( '<' at line 1' (err#0)
<- execute('02b5f135f611c1d7b0ec090182bc6cf5_body', '<body id="aboutUsPage">
<div id="wrapper">
<div id="header">
<div id="innerHeader">
<h1><span>The Mobile Makeover - Beauty Products</span></h1>
<div class="clear"></div>
<?php include("php/navigation.php"); ?>
<div class="clear"></div>
</div>
</div>
<div id="main">
<div id="content1" class="content vis">
<h2>Beauty products that we use</h2>
<div class="image1">
</div>
<p>We use a wide range of the finest products on the market today. Below is a short brief of just a few of the names which we believe give you the best results - we do not compromise when it comes to quality.<br /> - <em>Kelly Knight</em></p>
</div>
<div class="content vis norm">
<h2>Jessica</h2>
<div class="image3">
</div>
<p>The Jessica © nail products are de...', ...)= undef at cgitest.pl line 366
!! ERROR: 1064 CLEARED by call to execute method
<- execute("public_html/beauty-products-used.php", "http://www.themobilemakeover.co.uk/beauty-products-used.php", ...)= 1 at cgitest.pl line 367
<- DESTROY(DBI::st=HASH(3d6982c))= undef at cgitest.pl line 270
<- quote("http://www.themobilemakeover.co.uk/beauty-treatments.php")= "'http://www.themobilemakeover.co.uk/beauty-treatments.php'" at cgitest.pl line 271
<- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/beauty-treatments.php' ")= DBI::st=HASH(0x3d56edc) at cgitest.pl line 272
<- execute= '0E0' at cgitest.pl line 273
<- rows= '0' at cgitest.pl line 274
<- quote("The Mobile Makeover - Beauty Treatments")= "'The Mobile Makeover - Beauty Treatments'" at cgitest.pl line 289
<- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - Beauty Treatments' ")= DBI::st=HASH(0x3d6b48c) at cgitest.pl line 290
<- execute= '0E0' at cgitest.pl line 291
<- rows= '0' at cgitest.pl line 292
<- DESTROY(DBI::st=HASH(3d6c674))= undef at cgitest.pl line 287
<- do('CREATE TABLE IF NOT EXISTS `22e64cef7d70fa952ce7444f158e2c4e_body` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`bodyData` TEXT NOT NULL,
>>> EDIT <<<<<<
I tried to post full code but wouldn't allow:
.
..
...
my $headDataUpload = $dbh->prepare("INSERT INTO ? ( headData, headDataOutput ) VALUES ( ?, ? )") or die " error: Couldn't prepare : " . DBI->errstr;
my $bodyDataUpload = $dbh->prepare("INSERT INTO ? ( bodyData, bodyDataOutput ) VALUES ( ?, ? )") or die " error: Couldn't prepare : " . DBI->errstr;
my $insertData = $dbh->prepare("INSERT INTO page_names (linkFromRoot, linkTrue, page_name, table_name, navigation, location) VALUES ( ?, ?, ?, ?, ?, ? )") or die " error: Couldn't connect to database: " . DBI->errstr;
foreach( #mainPagesArray ) {
my $webpage = &extention(trim($_));
if( trim($webpage) ne trim($domain) ){
my $webpageQuote = $dbh->quote("http://www." . $webpage);
my $sth = $dbh->prepare("SELECT * FROM page_names WHERE linkTrue = $webpageQuote ") or die "Could not select from table" . $DBI::errstr;
$sth->execute();
if( $sth->rows == 0 ) {
#output display pages found
print "<span class=\"green\">http://www." . $webpage . "</span><br />\n";
my $md5Con = "http://www." . $webpage;
my $linkTrue = "http://www." . $webpage;
$webpage =~ s/^$domain//g;
my $linkFromRoot = $root . $webpage;
my $getTitleContents = get($md5Con);
my $stringPageName;
if( $getTitleContents =~ m/<title>([^<]*)<\/title>/g ) {
my #titles = ($1);
my $counter = 2;
while(#titles){
my $currentTitle = shift #titles;
my $titleQuoted = $dbh->quote($currentTitle);
my $sth = $dbh->prepare("SELECT * FROM page_names WHERE page_name = $titleQuoted ") or die "Could not select from table" . $DBI::errstr;
$sth->execute();
if( $sth->rows == 0 ) {
$stringPageName = $currentTitle;
last;
}else{
my $newTitle = $currentTitle . "(" . $counter . ")";
push(#titles, $newTitle);
$counter ++;
}
}
}else{
my #titles = ('Untitled');
my $counter = 2;
while(#titles){
my $currentTitle = shift #titles;
my $titleQuoted = $dbh->quote($currentTitle);
my $sth = $dbh->prepare("SELECT * FROM page_names WHERE page_name = $titleQuoted ") or die "Could not select from table" . $DBI::errstr;
$sth->execute();
if( $sth->rows == 0 ) {
$stringPageName = $currentTitle;
last;
}else{
my $newTitle = $currentTitle . "(" . $counter . ")";
push(#titles, $newTitle);
$counter ++;
}
}
}
my $page_name = $stringPageName;
my $table_name = md5_hex($md5Con);
my $navigation = "1";
my $location = "1";
my $bodyTable = md5_hex($md5Con) . "_body";
my $headerTable = md5_hex($md5Con) . "_header";
my $createBodyTable = "CREATE TABLE IF NOT EXISTS `$bodyTable` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`bodyData` TEXT NOT NULL,
`bodyDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
my $createHeadTable = "CREATE TABLE IF NOT EXISTS `$headerTable` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`headData` TEXT NOT NULL,
`headDataOutput` TEXT NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;";
my $fileContents;
if( $md5Con =~ m/\.php$/g ) {
my $ftp = Net::FTP->new($DB_ftpserver, Debug => 0) or die "Cannot connect to some.host.name: $#";
$ftp->login($DB_ftpuser, $DB_ftppass) or die "Cannot login ", $ftp->message;
$ftp->get("/" . $root . $webpage, "c:/perlscripts/" . md5_hex($md5Con) . "-code.php") or die $ftp->message;
my $file = "c:/perlscripts/" . md5_hex($md5Con) . "-code.php";
{
local( $/ ); # undefine the record seperator
open FILE, "<", $file or die "Cannot open:$!\n";
my $fileContents = <FILE>;
my $bodyContents;
my $headContents;
my #contentsArray = split( /<\/head>/is, $fileContents, 2);
#print $contentsArray[1];
if( scalar #contentsArray == 2 ){
$bodyContents = trim($contentsArray[1]);
$headContents = trim($contentsArray[0]) . "</head>";
#print $headContents . "\n";
$dbh->do($createBodyTable) or die " error: Couldn't create body table: " . DBI->errstr;
$dbh->do($createHeadTable) or die " error: Couldn't create header table: " . DBI->errstr;
$headDataUpload->execute($headerTable, $headContents, $headContents);
$bodyDataUpload->execute($bodyTable, $bodyContents, $bodyContents);
$insertData->execute($linkFromRoot, $linkTrue, $page_name, $table_name, $navigation, $location);
#unlink("c:/perlscripts/" . md5_hex($md5Con) . "-code.php");
}else{
print "<span class=\"red\">" . $md5Con . " cannot be used by our CMS, invalid data.</span><br />\n";
}
}
$ftp->quit;
}elsif( $md5Con =~ m/(?:(?:\.asp)|(?:\.aspx))$/g ){
}
}
}
}
}else{
print "<span class=\"red\"> error: No pages where found. This CMS is designed for pre-existing sites. Please contact support for more information.</span><br />\n";
}
...
..
.
It would have been helpful to see just your query and the error that resulted, separate from all the trace information.
It looks to me like you are trying to use a placeholder for the table name, something that mysql doesn't support.