Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
yii2bootstrap
Commits
b9137dfe
Commit
b9137dfe
authored
Nov 07, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sphinx command and query added.
parent
afcdcb9a
Changes
8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
729 additions
and
45 deletions
+729
-45
.travis.yml
.travis.yml
+1
-1
Command.php
extensions/sphinx/yii/sphinx/Command.php
+19
-0
Query.php
extensions/sphinx/yii/sphinx/Query.php
+537
-0
QueryBuilder.php
extensions/sphinx/yii/sphinx/QueryBuilder.php
+75
-0
Schema.php
extensions/sphinx/yii/sphinx/Schema.php
+9
-1
sphinx.conf
tests/unit/data/sphinx/sphinx.conf
+3
-0
sphinx.sql
tests/unit/data/sphinx/sphinx.sql
+0
-43
CommandTest.php
tests/unit/extensions/sphinx/CommandTest.php
+85
-0
No files found.
.travis.yml
View file @
b9137dfe
...
@@ -18,7 +18,7 @@ before_script:
...
@@ -18,7 +18,7 @@ before_script:
-
tests/unit/data/travis/cubrid-setup.sh
-
tests/unit/data/travis/cubrid-setup.sh
script
:
script
:
-
phpunit --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata
-
phpunit --coverage-clover tests/unit/runtime/coveralls/clover.xml --verbose --exclude-group mssql,oci,wincache,xcache,zenddata
,sphinx
after_script
:
after_script
:
-
php vendor/bin/coveralls
-
php vendor/bin/coveralls
extensions/sphinx/yii/sphinx/Command.php
0 → 100644
View file @
b9137dfe
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\sphinx
;
/**
* Class Command
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
Command
extends
\yii\db\Command
{
//
}
\ No newline at end of file
extensions/sphinx/yii/sphinx/Query.php
0 → 100644
View file @
b9137dfe
This diff is collapsed.
Click to expand it.
extensions/sphinx/yii/sphinx/QueryBuilder.php
0 → 100644
View file @
b9137dfe
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\sphinx
;
/**
* Class QueryBuilder
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @since 2.0
*/
class
QueryBuilder
extends
\yii\db\mysql\QueryBuilder
{
/**
* Generates a SELECT SQL statement from a [[Query]] object.
* @param Query $query the [[Query]] object from which the SQL statement will be generated
* @return array the generated SQL statement (the first array element) and the corresponding
* parameters to be bound to the SQL statement (the second array element).
*/
public
function
build
(
$query
)
{
$params
=
$query
->
params
;
$clauses
=
[
$this
->
buildSelect
(
$query
->
select
,
$query
->
distinct
,
$query
->
selectOption
),
$this
->
buildFrom
(
$query
->
from
),
$this
->
buildWhere
(
$query
->
where
,
$params
),
$this
->
buildGroupBy
(
$query
->
groupBy
),
$this
->
buildWithin
(
$query
->
within
),
$this
->
buildOrderBy
(
$query
->
orderBy
),
$this
->
buildLimit
(
$query
->
limit
,
$query
->
offset
),
$this
->
buildOption
(
$query
->
options
),
];
return
[
implode
(
$this
->
separator
,
array_filter
(
$clauses
)),
$params
];
}
/**
* @param array $columns
* @return string the ORDER BY clause built from [[query]].
*/
public
function
buildWithin
(
$columns
)
{
if
(
empty
(
$columns
))
{
return
''
;
}
$orders
=
[];
foreach
(
$columns
as
$name
=>
$direction
)
{
if
(
is_object
(
$direction
))
{
$orders
[]
=
(
string
)
$direction
;
}
else
{
$orders
[]
=
$this
->
db
->
quoteColumnName
(
$name
)
.
(
$direction
===
Query
::
SORT_DESC
?
' DESC'
:
''
);
}
}
return
'WITHIN GROUP ORDER BY '
.
implode
(
', '
,
$orders
);
}
/**
* @param array $options
* @return string the OPTION clause build from [[query]]
*/
public
function
buildOption
(
array
$options
)
{
if
(
empty
(
$options
))
{
return
''
;
}
$optionLines
=
[];
foreach
(
$options
as
$name
=>
$value
)
{
$optionLines
[]
=
$name
.
' = '
.
$value
;
}
return
'OPTION '
.
implode
(
', '
,
$optionLines
);
}
}
\ No newline at end of file
extensions/sphinx/yii/sphinx/Schema.php
View file @
b9137dfe
...
@@ -15,5 +15,13 @@ namespace yii\sphinx;
...
@@ -15,5 +15,13 @@ namespace yii\sphinx;
*/
*/
class
Schema
extends
\yii\db\mysql\Schema
class
Schema
extends
\yii\db\mysql\Schema
{
{
//
/**
* Creates a query builder for the database.
* This method may be overridden by child classes to create a DBMS-specific query builder.
* @return QueryBuilder query builder instance
*/
public
function
createQueryBuilder
()
{
return
new
QueryBuilder
(
$this
->
db
);
}
}
}
\ No newline at end of file
tests/unit/data/sphinx/sphinx.conf
View file @
b9137dfe
...
@@ -17,6 +17,7 @@ source yii2_test_article_src
...
@@ -17,6 +17,7 @@ source yii2_test_article_src
FROM
yii2_test_article
FROM
yii2_test_article
sql_attr_uint
=
id
sql_attr_uint
=
id
sql_attr_uint
=
author_id
sql_attr_timestamp
=
add_date
sql_attr_timestamp
=
add_date
sql_query_info
=
SELECT
*
FROM
yii2_test_article
WHERE
id
=$
id
sql_query_info
=
SELECT
*
FROM
yii2_test_article
WHERE
id
=$
id
...
@@ -38,6 +39,8 @@ source yii2_test_item_src
...
@@ -38,6 +39,8 @@ source yii2_test_item_src
FROM
yii2_test_item
FROM
yii2_test_item
sql_attr_uint
=
id
sql_attr_uint
=
id
sql_attr_uint
=
category_id
sql_attr_float
=
price
sql_attr_timestamp
=
add_date
sql_attr_timestamp
=
add_date
sql_query_info
=
SELECT
*
FROM
yii2_test_item
WHERE
id
=$
id
sql_query_info
=
SELECT
*
FROM
yii2_test_item
WHERE
id
=$
id
...
...
tests/unit/data/sphinx/sphinx.sql
View file @
b9137dfe
-- phpMyAdmin SQL Dump
-- version 3.5.0
-- http://www.phpmyadmin.net
--
-- Host: 10.10.50.201
-- Generation Time: Nov 01, 2013 at 04:38 PM
-- Server version: 5.1.69-log
-- PHP Version: 5.3.3
SET
SQL_MODE
=
"NO_AUTO_VALUE_ON_ZERO"
;
SET
SQL_MODE
=
"NO_AUTO_VALUE_ON_ZERO"
;
SET
time_zone
=
"+00:00"
;
SET
time_zone
=
"+00:00"
;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */
;
/*!40101 SET NAMES utf8 */
;
--
-- Database: `yiiexample`
--
-- --------------------------------------------------------
--
-- Table structure for table `yii2_test_article`
--
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_article`
(
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_article`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`title`
varchar
(
255
)
NOT
NULL
,
`title`
varchar
(
255
)
NOT
NULL
,
...
@@ -35,20 +10,10 @@ CREATE TABLE IF NOT EXISTS `yii2_test_article` (
...
@@ -35,20 +10,10 @@ CREATE TABLE IF NOT EXISTS `yii2_test_article` (
PRIMARY
KEY
(
`id`
)
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
3
;
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
3
;
--
-- Dumping data for table `yii2_test_article`
--
INSERT
INTO
`yii2_test_article`
(
`id`
,
`title`
,
`content`
,
`author_id`
,
`create_date`
)
VALUES
INSERT
INTO
`yii2_test_article`
(
`id`
,
`title`
,
`content`
,
`author_id`
,
`create_date`
)
VALUES
(
1
,
'About cats'
,
'This article is about cats'
,
1
,
'2013-10-23 00:00:00'
),
(
1
,
'About cats'
,
'This article is about cats'
,
1
,
'2013-10-23 00:00:00'
),
(
2
,
'About dogs'
,
'This article is about dogs'
,
2
,
'2013-11-15 00:00:00'
);
(
2
,
'About dogs'
,
'This article is about dogs'
,
2
,
'2013-11-15 00:00:00'
);
-- --------------------------------------------------------
--
-- Table structure for table `yii2_test_item`
--
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_item`
(
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_item`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
255
)
NOT
NULL
,
`name`
varchar
(
255
)
NOT
NULL
,
...
@@ -58,14 +23,6 @@ CREATE TABLE IF NOT EXISTS `yii2_test_item` (
...
@@ -58,14 +23,6 @@ CREATE TABLE IF NOT EXISTS `yii2_test_item` (
PRIMARY
KEY
(
`id`
)
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
3
;
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
3
;
--
-- Dumping data for table `yii2_test_item`
--
INSERT
INTO
`yii2_test_item`
(
`id`
,
`name`
,
`description`
,
`category_id`
,
`price`
)
VALUES
INSERT
INTO
`yii2_test_item`
(
`id`
,
`name`
,
`description`
,
`category_id`
,
`price`
)
VALUES
(
1
,
'pencil'
,
'Simple pencil'
,
1
,
2
.
5
),
(
1
,
'pencil'
,
'Simple pencil'
,
1
,
2
.
5
),
(
2
,
'table'
,
'Wooden table'
,
2
,
100
);
(
2
,
'table'
,
'Wooden table'
,
2
,
100
);
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */
;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */
;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
;
tests/unit/extensions/sphinx/CommandTest.php
0 → 100644
View file @
b9137dfe
<?php
namespace
yiiunit\extensions\sphinx
;
use
yii\db\DataReader
;
/**
* @group sphinx
*/
class
CommandTest
extends
SphinxTestCase
{
public
function
testExecute
()
{
$db
=
$this
->
getConnection
();
$sql
=
'SELECT COUNT(*) FROM yii2_test_item_index WHERE MATCH(\'wooden\')'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'bad SQL'
);
$this
->
setExpectedException
(
'\yii\db\Exception'
);
$command
->
execute
();
}
public
function
testQuery
()
{
$db
=
$this
->
getConnection
();
// query
$sql
=
'SELECT * FROM yii2_test_item_index'
;
$reader
=
$db
->
createCommand
(
$sql
)
->
query
();
$this
->
assertTrue
(
$reader
instanceof
DataReader
);
// queryAll
$rows
=
$db
->
createCommand
(
'SELECT * FROM yii2_test_item_index'
)
->
queryAll
();
$this
->
assertEquals
(
2
,
count
(
$rows
));
$row
=
$rows
[
1
];
$this
->
assertEquals
(
2
,
$row
[
'id'
]);
$this
->
assertEquals
(
2
,
$row
[
'category_id'
]);
$rows
=
$db
->
createCommand
(
'SELECT * FROM yii2_test_item_index WHERE id=10'
)
->
queryAll
();
$this
->
assertEquals
([],
$rows
);
// queryOne
$sql
=
'SELECT * FROM yii2_test_item_index ORDER BY id ASC'
;
$row
=
$db
->
createCommand
(
$sql
)
->
queryOne
();
$this
->
assertEquals
(
1
,
$row
[
'id'
]);
$this
->
assertEquals
(
1
,
$row
[
'category_id'
]);
$sql
=
'SELECT * FROM yii2_test_item_index ORDER BY id ASC'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
prepare
();
$row
=
$command
->
queryOne
();
$this
->
assertEquals
(
1
,
$row
[
'id'
]);
$this
->
assertEquals
(
1
,
$row
[
'category_id'
]);
$sql
=
'SELECT * FROM yii2_test_item_index WHERE id=10'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertFalse
(
$command
->
queryOne
());
// queryColumn
$sql
=
'SELECT * FROM yii2_test_item_index'
;
$column
=
$db
->
createCommand
(
$sql
)
->
queryColumn
();
$this
->
assertEquals
(
range
(
1
,
2
),
$column
);
$command
=
$db
->
createCommand
(
'SELECT id FROM yii2_test_item_index WHERE id=10'
);
$this
->
assertEquals
([],
$command
->
queryColumn
());
// queryScalar
$sql
=
'SELECT * FROM yii2_test_item_index ORDER BY id ASC'
;
$this
->
assertEquals
(
$db
->
createCommand
(
$sql
)
->
queryScalar
(),
1
);
$sql
=
'SELECT id FROM yii2_test_item_index ORDER BY id ASC'
;
$command
=
$db
->
createCommand
(
$sql
);
$command
->
prepare
();
$this
->
assertEquals
(
1
,
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'SELECT id FROM yii2_test_item_index WHERE id=10'
);
$this
->
assertFalse
(
$command
->
queryScalar
());
$command
=
$db
->
createCommand
(
'bad SQL'
);
$this
->
setExpectedException
(
'\yii\db\Exception'
);
$command
->
query
();
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment