PAM EXAM configuration dependency demanding older JAR when newer is available - configuration

I'm struggling with a PAX EXAM configuration for integration tests of a project I've started working some weeks ago.
The major problem are regarding the dependencies of the bundles I'm intending to test, but I was always able to evolve for each problem, but now I'm really stuck.
Below I'm listing the current version of my #Configuration method:
#Configuration
public Option[] configure() {
// Runs outside the OSGi framework
return options(
junitBundles(),
wrappedBundle( mavenBundle( "antlr", "antlr" ).version( "2.7.7" ) ),
wrappedBundle( mavenBundle( "com.fasterxml", "classmate" ).version( "1.3.0" ) ),
wrappedBundle( mavenBundle( "org.javassist", "javassist" ).version( "3.18.1-GA" ) ),
wrappedBundle( mavenBundle( "org.jboss.logging", "jboss-logging" ).version( "3.1.0.GA" ) ),
wrappedBundle( mavenBundle( "dom4j", "dom4j" ).version( "1.6.1" ) ),
//wrappedBundle( mavenBundle( "org.hibernate.javax.persistence", "hibernate-jpa-2.0-api" ).version( "1.0.1.Final" ) ),
mavenBundle( "javax.persistence", "com.springsource.javax.persistence" ).version( "2.0.0" ),
wrappedBundle( mavenBundle( "org.jboss.spec.javax.transaction", "jboss-transaction-api_1.1_spec" ).version( "1.0.1.Final" ) ),
//wrappedBundle( mavenBundle( "javax.transaction", "javax.transaction-api" ).version( "1.2" ) ),
//wrappedBundle( mavenBundle( "javax.enterprise", "cdi-api" ).version( "1.0-SP4" ) ),
//wrappedBundle( mavenBundle( "org.jboss.spec.javax.interceptor", "jboss-interceptors-api_1.1_spec" ).version( "1.0.0.Beta1" ) ),
wrappedBundle( mavenBundle( "org.jboss", "jandex" ).version( "1.0.3.Final" ) ),
wrappedBundle( mavenBundle( "org.hibernate", "hibernate-core" ).version( "4.2.21.Final" ) ),
wrappedBundle( mavenBundle( "org.springframework", "spring-beans" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.beans" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-context" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.context" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-core" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.core" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-aop" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.aop" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-jdbc" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.jdbc" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "org.springframework", "spring-tx" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.tx" ).bundleVersion( "3.2.5.RELEASE" ),
wrappedBundle( mavenBundle( "aopalliance", "aopalliance" ).version( "1.0" ) ),
wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-core" ).version( "1.2.1" ) ),
wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-annotation" ).version( "1.2.1" ) ),
wrappedBundle( mavenBundle( "org.springframework.osgi", "spring-osgi-extender" ).version( "1.2.1" ) ),
wrappedBundle( mavenBundle( "commons-lang", "commons-lang" ).version( "2.6" ) ),
wrappedBundle( mavenBundle( "org.hibernate.common", "hibernate-commons-annotations" ).version( "4.0.2.Final" ) );
}
I removed our business dependencies because they are not necessary for the explanation.
Spring OSGI dependencies ("spring-osgi-core", "spring-osgi-annotation", etc) are dependent of version "2.5.6" of Spring Framework, which I'm already fulfilling with versions "3.2.5.RELEASE" of those libs, but for some reason the old versions are still getting enforced as could be seen by erros below:
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))] Unresolved requirements: [[br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0))]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:748)
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0): missing requirement [br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository) [caused by: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))]] Unresolved requirements: [[br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:748)
ERROR: Bundle br.com.mycompany.myapplication.api.log.application-log-service [40] Error starting file:/tmp/1533155354575-0/pax-exam-downloads/br.com.mycompany.myapplication.api.log.application-log-service_1.46.0.SNAPSHOT.jar (org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0): missing requirement [br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository) [caused by: Unable to resolve br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0): missing requirement [br.com.mycompany.myapplication.osgi.entity.interceptor.entity-interceptor [39](R 39.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.osgi.extensions.annotation)(version>=1.2.0)) [caused by: Unable to resolve org.springframework.osgi.extensions.annotations [33](R 33.0): missing requirement [org.springframework.osgi.extensions.annotations [33](R 33.0)] osgi.wiring.package; (&(osgi.wiring.package=org.springframework.beans)(version>=2.5.6)(!(version>=4.0.0)))]] Unresolved requirements: [[br.com.mycompany.myapplication.api.log.application-log-service [40](R 40.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.myapplication.osgi.entity.interceptor.repository)])
org.osgi.framework.BundleException: Unable to resolve br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0): missing requirement [br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.idpclient.model) Unresolved requirements: [[br.com.mycompany.myapplication.api.log.listener.application-log-listener [41](R 41.0)] osgi.wiring.package; (osgi.wiring.package=br.com.mycompany.idpclient.model)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.lang.Thread.run(Thread.java:748)
Does anyone have any ideas why is this happening?
Thanks a lot and best regards!

You should not wrap all the bundles on your own. Sometimes making an OSGi bundle requires more than the auto wrapping can provide. A good approach is to check what Apache Karaf uses.
Spring and many other libs you need are provided by service mix bundles.
Try this:
Download and start Apache Karaf 4.1.5
feature:install spring hibernate transaction
la -s
So you see what bundles karaf installs for spring. These should work better for your case.
Apart from that I would really try to get away from spring if you want to use OSGi. Spring was known to cause lots of issues in OSGi and the newer versions are even less compatible.

I was able to workaround the problem by wrapping the "org.springframework" dependencies in order to change their manifest, like below:
wrappedBundle( mavenBundle( "org.springframework", "spring-beans" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.beans" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-core" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.core" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-context" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.context" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-jdbc" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.jdbc" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-aop" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.aop" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-orm" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.orm" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
wrappedBundle( mavenBundle( "org.springframework", "spring-tx" ).version( "3.2.5.RELEASE" ) ).bundleSymbolicName( "org.springframework.transaction" ).bundleVersion( "3.2.5.RELEASE" )
.exports( "*;version=3.2.5.RELEASE" ).overwriteManifest( WrappedUrlProvisionOption.OverwriteMode.MERGE ),
With this change, the "org.springframework.osgi" dependencies stop asking for the older "2.5.6" version of "org.springframework" libs.
Now I'm facing a different problem to get everyghing running as exposed on another question: PAX EXAM Rest Endpoint not available for felix integration test.

Related

ERROR 1242 Subquery returns more than 1 line in SQL

I have a view in SQL that when I want to open it gives me the following message: #1242 - Subquery returns more than 1 line.
How can I correct this query considering my sql script?
My code is:
SELECT
`sc`.`id` AS `id`,
`sc`.`id_agente_solicitado` AS `id_agente_solicitado`,
`sc`.`id_agente_solicitante` AS `id_agente_solicitante`,
`sc`.`fecha_solicitada` AS `fecha`,
`sc`.`horario_solicitado` AS `hora`,
`sc`.`pendiente` AS `pendiente`,
'1' AS `tipo`,
'Cambios de horarios' AS `grupo`,
'1' AS `grupo_numero`,
CONCAT(`a`.`nombres`, ' ', `a`.`apellidos`) AS `agente_solicitado_nombre`,
(
SELECT
CONCAT(
`sigsiste_bd`.`agentes`.`nombres`,
' ',
`sigsiste_bd`.`agentes`.`apellidos`
)
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `agente_solicitante_nombre`,
(
SELECT
`sigsiste_bd`.`agentes`.`imagen_perfil`
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `imagen_perfil_solicitante`,
`a`.`imagen_perfil` AS `imagen_perfil_solicitado`,
DAYNAME(`sc`.`fecha_solicitada`) AS `nombre_dia`,
CONCAT(
CONVERT(
DATE_FORMAT(`sc`.`fecha_solicitada`, '%d') USING utf8mb4
),
' de ',
CONVERT(
MONTHNAME(`sc`.`fecha_solicitada`) USING utf8mb4
),
' de ',
CONVERT(
DATE_FORMAT(`sc`.`fecha_solicitada`, '%Y') USING utf8mb4
)
) AS `nombre_mes`,
(
SELECT
CONCAT(' ', `det`.`ingreso`)
FROM
(
`sigsiste_bd`.`planilla_horarios_det` `det`
LEFT JOIN `sigsiste_bd`.`planilla_horarios_cab` `cab`
ON
(
(
`cab`.`id_planilla_horarios_cab` = `det`.`id_planilla_horarios_cab`
)
)
)
WHERE
(
(
STR_TO_DATE(
CONCAT(
`cab`.`ano_correspondiente`,
',',
`cab`.`mes_correspondiente`,
',',
`det`.`dia`
),
'%Y,%m,%d'
) = `sc`.`fecha_solicitada`
) AND(
`sc`.`id_agente_solicitante` = `det`.`id_agente`
)
)
) AS `cambio_por`
FROM
(
`sigsiste_bd`.`solicitudes_cambio_horario` `sc`
LEFT JOIN `sigsiste_bd`.`agentes` `a`
ON
(
(
`a`.`id_agente` = `sc`.`id_agente_solicitado`
)
)
)
UNION ALL
SELECT
`sc`.`id` AS `id`,
`sc`.`id_agente_solicitado` AS `id_agente_solicitado`,
`sc`.`id_agente_solicitante` AS `id_agente_solicitante`,
`sc`.`fecha_cobertura` AS `fecha`,
`sc`.`horario_cobertura` AS `hora`,
`sc`.`pendiente` AS `pendiente`,
'2' AS `tipo`,
'Coberturas' AS `grupo`,
'2' AS `grupo_numero`,
CONCAT(`a`.`nombres`, ' ', `a`.`apellidos`) AS `agente_solicitado_nombre`,
(
SELECT
CONCAT(
`sigsiste_bd`.`agentes`.`nombres`,
' ',
`sigsiste_bd`.`agentes`.`apellidos`
)
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `agente_solicitante_nombre`,
(
SELECT
`sigsiste_bd`.`agentes`.`imagen_perfil`
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `imagen_perfil_solicitante`,
`a`.`imagen_perfil` AS `imagen_perfil_solicitado`,
DAYNAME(`sc`.`fecha_cobertura`) AS `nombre_dia`,
CONCAT(
CONVERT(
DATE_FORMAT(`sc`.`fecha_cobertura`, '%d') USING utf8mb4
),
' de ',
CONVERT(
MONTHNAME(`sc`.`fecha_cobertura`) USING utf8mb4
),
' de ',
CONVERT(
DATE_FORMAT(`sc`.`fecha_cobertura`, '%Y') USING utf8mb4
)
) AS `nombre_mes`,
'' AS `cambio_por`
FROM
(
`sigsiste_bd`.`solicitudes_cobertura` `sc`
LEFT JOIN `sigsiste_bd`.`agentes` `a`
ON
(
(
`a`.`id_agente` = `sc`.`id_agente_solicitado`
)
)
)
UNION ALL
SELECT
`sc`.`id` AS `id`,
`sc`.`id_agente_solicitado` AS `id_agente_solicitado`,
`sc`.`id_agente_solicitante` AS `id_agente_solicitante`,
`sc`.`fecha_devolucion` AS `fecha`,
`sc`.`horario_devolucion` AS `hora`,
`sc`.`pendiente` AS `pendiente`,
'3' AS `tipo`,
'Devoluciones' AS `grupo`,
'3' AS `grupo_numero`,
CONCAT(`a`.`nombres`, ' ', `a`.`apellidos`) AS `agente_solicitado_nombre`,
(
SELECT
CONCAT(
`sigsiste_bd`.`agentes`.`nombres`,
' ',
`sigsiste_bd`.`agentes`.`apellidos`
)
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `agente_solicitante_nombre`,
(
SELECT
`sigsiste_bd`.`agentes`.`imagen_perfil`
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `imagen_perfil_solicitante`,
`a`.`imagen_perfil` AS `imagen_perfil_solicitado`,
DAYNAME(`sc`.`fecha_devolucion`) AS `nombre_dia`,
CONCAT(
CONVERT(
DATE_FORMAT(`sc`.`fecha_devolucion`, '%d') USING utf8mb4
),
' de ',
CONVERT(
MONTHNAME(`sc`.`fecha_devolucion`) USING utf8mb4
),
' de ',
CONVERT(
DATE_FORMAT(`sc`.`fecha_devolucion`, '%Y') USING utf8mb4
)
) AS `nombre_mes`,
'' AS `cambio_por`
FROM
(
`sigsiste_bd`.`solicitudes_devoluciones` `sc`
LEFT JOIN `sigsiste_bd`.`agentes` `a`
ON
(
(
`a`.`id_agente` = `sc`.`id_agente_solicitado`
)
)
)
I have a view in SQL that after trying to open it gives me the following message: #1242 - Subquery returns more than 1 line.
How can I correct my query?
It is not possible to be sure, as you have not included nearly enough detail, but I suspect the error is being caused by the subquery for cambio_por as the other subqueries appear to be based on the PK -
(
SELECT
CONCAT(' ', `det`.`ingreso`)
FROM
(
`sigsiste_bd`.`planilla_horarios_det` `det`
LEFT JOIN `sigsiste_bd`.`planilla_horarios_cab` `cab`
ON
(
(
`cab`.`id_planilla_horarios_cab` = `det`.`id_planilla_horarios_cab`
)
)
)
WHERE
(
(
STR_TO_DATE(
CONCAT(
`cab`.`ano_correspondiente`,
',',
`cab`.`mes_correspondiente`,
',',
`det`.`dia`
),
'%Y,%m,%d'
) = `sc`.`fecha_solicitada`
) AND(
`sc`.`id_agente_solicitante` = `det`.`id_agente`
)
)
) AS `cambio_por`
to test you could try replacing it with an empty string, as you have for the other two selects -
'' AS `cambio_por`
Each of the three outer selects has two subqueries in the select list to retrieve values from sigsiste_bd.agentes based on sc.id_agente_solicitante. These should probably be replaced by another join.
...
(
SELECT
CONCAT(
`sigsiste_bd`.`agentes`.`nombres`,
' ',
`sigsiste_bd`.`agentes`.`apellidos`
)
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `agente_solicitante_nombre`,
(
SELECT
`sigsiste_bd`.`agentes`.`imagen_perfil`
FROM
`sigsiste_bd`.`agentes`
WHERE
(
`sigsiste_bd`.`agentes`.`id_agente` = `sc`.`id_agente_solicitante`
)
) AS `imagen_perfil_solicitante`,
...
FROM
(
`sigsiste_bd`.`solicitudes_cambio_horario` `sc`
LEFT JOIN `sigsiste_bd`.`agentes` `a`
ON
(
(
`a`.`id_agente` = `sc`.`id_agente_solicitado`
)
)
)
would become
...
CONCAT(`agente_solicitante`.`nombres`, ' ', `agente_solicitante`.`apellidos`) AS `agente_solicitante_nombre`,
`agente_solicitante`.`imagen_perfil` AS `imagen_perfil_solicitante`,
...
FROM `sigsiste_bd`.`solicitudes_cambio_horario` `sc`
LEFT JOIN `sigsiste_bd`.`agentes` `a`
ON `a`.`id_agente` = `sc`.`id_agente_solicitado`
LEFT JOIN `sigsiste_bd`.`agentes` `agente_solicitante`
ON `agente_solicitante`.`id_agente` = `sc`.`id_agente_solicitante`
Your expression for nombre_mes can be simplified -
/* From */
CONCAT(
CONVERT(
DATE_FORMAT(`sc`.`fecha_cobertura`, '%d') USING utf8mb4
),
' de ',
CONVERT(
MONTHNAME(`sc`.`fecha_cobertura`) USING utf8mb4
),
' de ',
CONVERT(
DATE_FORMAT(`sc`.`fecha_cobertura`, '%Y') USING utf8mb4
)
) AS `nombre_mes`,
/* To */
CONVERT(DATE_FORMAT(`sc`.`fecha_solicitada`, '%d de %M de %Y') USING utf8mb4) AS `nombre_mes`,

Convert MYSQL RAW included hash(encrypt) query to Laravel eloquent query

This is the raw query
"SELECT * FROM re_customer
WHERE LOWER(email) = '" . $input['email'] . "'
AND
(password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $input['password'] . "')))))
OR password = '" . md5( $input['password'] ) . "')
AND status = '1'";
I tried
$customer = DB::connection( 'oc' )
->table( Customer::$customerTable )
->where( DB::raw( 'LOWER(email)' ), '=', mb_strtolower( $input['email'] ) )
->whereRaw( "(password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('?'))))) OR password = '?')", [
$input['password'],
md5($input['password'])
] )
->where( 'status', 1 )
->first();
But not working for me (both query results are not same). Can you please address me that what wrong on this query.
I solved the query conversion.
$customer = DB::connection( 'oc' )
->table( Customer::$customerTable )
->where( DB::raw( 'LOWER(email)' ), '=', mb_strtolower( $input['email'] ) )
->where( 'status', 1 )
->where( function ( $query ) use ( $input ) {
$query->whereRaw( "password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1(?)))))", $input['password'] )
->orWhere( 'password', '=', md5( $input['password'] ) );
} )
->first();
this is working like a charm

Get Weekstartdate and enddate by date

How to get weekstartdate and weekenddate by passing one date ?
When I pass 2016-07-27 01:24:10.510, I need this output
startdate: 2016-07-24 00:00:00.000 which is Sunday
enddate: 2016-07-30 00:00:00.000 which is Saturday
I used this code, but this is returning wrong output
DECLARE #Date DATE = getdate()
SELECT d.WeekStart,
Weekend = CASE WHEN DATEADD(DAY, 7, WeekStart) > StartOfNextMonth
THEN StartOfNextMonth
ELSE DATEADD(DAY, 7, WeekStart)
END
FROM ( SELECT WeekStart = DATEADD(DAY,
((DATEPART(DAY, #Date) - 1) / 7.0) * 7,
DATEADD(MONTH, DATEDIFF(MONTH, 0, #Date), 0)),
StartOfNextMonth = DATEADD(MONTH, DATEDIFF(MONTH, 0, #Date) + 1, 0)
) AS d;
Any Ideas?
Could also be a Table-Valued Function
Declare #Date Date = GetDate()
Select weekstartdate = DateAdd(DD,1-DatePart(DW,#Date),#Date )
,weekenddate = DateAdd(DD,7-DatePart(DW,#Date),#Date )
Returns
weekstartdate weekenddate
2016-07-24 2016-07-30
Assuming that ##DATEFIRST is 7:
declare #Samples as Table ( Sample DateTime );
insert into #Samples ( Sample ) values
( '2016-07-27 01:24:10.510' ),
( '2016-07-20 00:00:00.000' ),
( '2016-07-21 00:00:00.000' ),
( '2016-07-22 00:00:00.000' ),
( '2016-07-23 00:00:00.000' ),
( '2016-07-24 00:00:00.000' ),
( '2016-07-25 00:00:00.000' ),
( '2016-07-26 00:00:00.000' ),
( '2016-07-27 00:00:00.000' ),
( '2016-07-28 00:00:00.000' ),
( '2016-07-29 00:00:00.000' );
select Sample,
DateAdd( day, 1 - DatePart( weekday, Sample ), Cast( Sample as Date ) ) as [StartOfWeek],
DateAdd( day, 7 - DatePart( weekday, Sample ), Cast( Sample as Date ) ) as [EndOfWeek]
from #Samples;

how to use clause where and group with 2 paramater in code igniter

I have model like this
Model:
public function lihatgajiharian($id,$tglitung){
$status='m';
$this->db->select('count( tgl ) AS total, absen.id, pegawai.nama, pegawai.bagian, pegawai.bagian, pegawai.tglmasuk, gaji.jenis_gaji, gaji.jumlah, gajiharian.id_gajiharian, gajiharian.status, gajiharian.tgldigaji,
(CASE WHEN (weekday( tgl ) <=3) THEN date( tgl + INTERVAL( 3 - weekday( tgl ) )DAY )
ELSE date( tgl + INTERVAL( 3 +7 - weekday( tgl ) )DAY )END) AS tglitung');
$this->db->from('absen');
$this->db->join('pegawai', 'pegawai.id = absen.id');
$this->db->join('gaji', 'gaji.id = pegawai.id');
$this->db->join('gajiharian', 'gajiharian.= absen.id','left');
$this->db->where('absen.id',$id);
$this->db->where('absen.status',$status);
$this->db->group_by('absen.id');
$this->db->group_by('tglitung');
$this->db->having('tglitung', $tglitung);
$query = $this->db->get();
return $query->row();
and appear error,
Error Number: 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 'absen.idWHEREabsen.id= '15' ANDabsen.status= 'm' GROUP BYabs' at line 6
but if I try run query in sql like this
Check near third join gajiharian you have put only dot there not with column add it and problem will be solved...
$status='m';
$this->db->select('count( tgl ) AS total, absen.id, pegawai.nama, pegawai.bagian, pegawai.bagian, pegawai.tglmasuk, gaji.jenis_gaji, gaji.jumlah, gajiharian.id_gajiharian, gajiharian.status, gajiharian.tgldigaji,
(CASE WHEN (weekday( tgl ) <=3) THEN date( tgl + INTERVAL( 3 - weekday( tgl ) )DAY )
ELSE date( tgl + INTERVAL( 3 +7 - weekday( tgl ) )DAY )END) AS tglitung');
$this->db->from('absen');
$this->db->join('pegawai', 'pegawai.id = absen.id');
$this->db->join('gaji', 'gaji.id = pegawai.id');
$this->db->join('gajiharian', 'gajiharian.column= absen.id','left'); //in this line problem occurs
$this->db->where('absen.id',$id);
$this->db->where('absen.status',$status);
$this->db->group_by('absen.id');
$this->db->group_by('tglitung');
$this->db->having('tglitung', $tglitung);
$query = $this->db->get();
return $query->row();

SQL Syntax error. Where is my syntatic mistake?

I can't for the life of me spot my typo!
UPDATE orders o, orders_total_couponz otc
SET o.total_paid = o.total_paid - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
SET o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
SET o.total_paid_tax_excl = o.total_paid_tax_excl - otc.converted_value,
SET o.total_paid_tax_real = o.total_paid_tax_real - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
SET o.total_products = o.total_products - otc.converted_value,
SET o.total_products_wt = o.total_products_wt - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) )
WHERE o.id_order = otc.orders_id
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 'SET o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 ' at line 3
Use the set keyword only once, and comma-separate the values to set:
UPDATE orders o, orders_total_couponz otc
SET o.total_paid = o.total_paid - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_excl = o.total_paid_tax_excl - otc.converted_value,
o.total_paid_tax_real = o.total_paid_tax_real - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_products = o.total_products - otc.converted_value,
o.total_products_wt = o.total_products_wt - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) )
WHERE o.id_order = otc.orders_id
Do not use SET again and again. Use command like:
UPDATE orders o, orders_total_couponz otc
SET o.total_paid = o.total_paid - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_incl = o.total_paid_tax_incl - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_paid_tax_excl = o.total_paid_tax_excl - otc.converted_value,
o.total_paid_tax_real = o.total_paid_tax_real - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) ),
o.total_products = o.total_products - otc.converted_value,
o.total_products_wt = o.total_products_wt - ( otc.converted_value * ( 1 + ( otc.tax_rate / 100 ) ) )
WHERE o.id_order = otc.orders_id