问:
wp_update_post category from anchor click
Would like to change and update a post category using wp_update_post. The category should be changed by clicking  or <button>

As far as I can see, this should apply the update to the post;

```<code>$live_paused = array(
'post_category' => 6
  );

// Update the post into the database
  wp_update_post( $live_paused );
</code>```

But how can I turn add this function to this

```<code> echo '<a href="" id=""><i class="fa fa-pause"></i></a>';
</code>```

Edit - further information

Update Post Code in functions of theme - not tested yet.

```<code>function live_paused_status( $post_id ){
if (current_user_can('edit_post', $post->ID)) {

    $live_paused = array(
        'post_category' => 6
    );
    echo '<a href="" id=""><button title="" data-toggle="tooltip" class="campaigns-link-button" type="button" data-original-title="Pause Campaign"><i class="fa fa-pause"></i></button></a>';

    // unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'live_paused_status');

    // update the post, which calls save_post again
    wp_update_post( $live_paused );

    // re-hook this function
    add_action('save_post', 'live_paused_status');
 }
}

add_action('save_post', 'live_paused_status');
</code>```

Loop

```<code> <?php $query = new WP_Query( array( 'post_type' => 'campaigns'));?>
    <?php if ($query->have_posts()) : while ( $query->have_posts() ) : $query->the_post(); ?>
      <div class="card">
        <div class="card-footer">
          <div class="row">
            <div class="col-4 campaigns-link">
              <?php echo live_paused_status(); ?>
            </div>
          </div>
        </div>
      </div>
   <?php endwhile; wp_reset_postdata(); ?>
</code>```

答:
You need to make an AJAX request to a script that you hook up. Hooking up AJAX in WordPress is a little weird, but rather than try to do it for you, you should look at the documentation in the WordPress Codex:

https://codex.wordpress.org/AJAX_in_Plugins

You are going to add an action that will basically be passed the post category ID from a form input, you will use JS to send that in a POST request, and then you will grab that ID and update the category.

Hope this helps.

EDIT

```<code><?php

add_action( 'wp_ajax_custom_update_category', 'custom_update_category' );

function custom_update_category() {
    $cat_id = sanitize_text_field( $_POST['cat_id']); //passed from AJAX. Make sure to escape it just in case.
    # update the category here with $cat_id
}
</code>```

To try to refine my answer even more, without writing it for you:

Create your form. I imagine this having some type of select input with the name="cat_id", and then the value of each option as the $cat_id in a loop in the WP template

You need to create a POST request with AJAX containing a cat_id parameter (pulls this from the select input's value). Here's one I have made in the past.

```<code>      var cat_id = $('#product-cat-select').val();

      $.ajax({
        type : "POST",
        url : ajaxurl,
        data : {
          action: "custom_update_category",
          cat_id: cat_id
        },
        success: function(response) {
          console.log( response );
        }
     });
</code>```

Notice that I named the action the same thing as the suffix on the add_action in my example (custom_update_category). The cat_id is being grabbed from the select input and then sent up in the data object of the AJAX request.

Using that data object, I can grab the $cat_id within my PHP within that script.

That action name is really the key.

Body:
Would like to change and update a post category using wp_update_post. The category should be changed by clicking  or <button>

As far as I can see, this should apply the update to the post;

$live_paused = array(
'post_category' => 6
  );

// Update the post into the database
  wp_update_post( $live_paused );

But how can I turn add this function to this

 echo '';

Edit - further information

Update Post Code in functions of theme - not tested yet.

function live_paused_status( $post_id ){
if (current_user_can('edit_post', $post->ID)) {

    $live_paused = array(
        'post_category' => 6
    );
    echo '<button title="" data-toggle="tooltip" class="campaigns-link-button" type="button" data-original-title="Pause Campaign"></button>';

    // unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'live_paused_status');

    // update the post, which calls save_post again
    wp_update_post( $live_paused );

    // re-hook this function
    add_action('save_post', 'live_paused_status');
 }
}

add_action('save_post', 'live_paused_status');

Loop

 <?php $query = new WP_Query( array( 'post_type' => 'campaigns'));?>
    <?php if ($query->have_posts()) : while ( $query->have_posts() ) : $query->the_post(); ?>

              <?php echo live_paused_status(); ?>

   <?php endwhile; wp_reset_postdata(); ?>

Body:
You need to make an AJAX request to a script that you hook up. Hooking up AJAX in WordPress is a little weird, but rather than try to do it for you, you should look at the documentation in the WordPress Codex:

https://codex.wordpress.org/AJAX_in_Plugins

You are going to add an action that will basically be passed the post category ID from a form input, you will use JS to send that in a POST request, and then you will grab that ID and update the category.

Hope this helps.

EDIT

<?php

add_action( 'wp_ajax_custom_update_category', 'custom_update_category' );

function custom_update_category() {
    $cat_id = sanitize_text_field( $_POST['cat_id']); //passed from AJAX. Make sure to escape it just in case.
    # update the category here with $cat_id
}

To try to refine my answer even more, without writing it for you:

Create your form. I imagine this having some type of select input with the name="cat_id", and then the value of each option as the $cat_id in a loop in the WP template

You need to create a POST request with AJAX containing a cat_id parameter (pulls this from the select input's value). Here's one I have made in the past.

      var cat_id = $('#product-cat-select').val();

      $.ajax({
        type : "POST",
        url : ajaxurl,
        data : {
          action: "custom_update_category",
          cat_id: cat_id
        },
        success: function(response) {
          console.log( response );
        }
     });

Notice that I named the action the same thing as the suffix on the add_action in my example (custom_update_category). The cat_id is being grabbed from the select input and then sent up in the data object of the AJAX request.

Using that data object, I can grab the $cat_id within my PHP within that script.

That action name is really the key.


来源: stackexchange

问:
How can I dynamically create a new .java file from a Java program?
I want to create a one .java from the Java program.  When I run the program, automatically one Java file will created in my project, and also create some run time (dynamic) variable in that file.  How can I do this?

I know for this I have to use a Reflection API like Class and Method, but what are the methods in Class and Method to do this?

答:
No, you can't generate new .java files using Reflection. You could perhaps create a new class, and use this class, in runtime, but you can't write that class out to file in the form of a .java source file.

Have a look at the JustAdd framework for instance. This framework solves this type of problems IIRC.

ContentLicense: CC BY-SA 2.5


问:
lucene title/content searching
I'm storing my lucene docs like so:

```<code>Document doc = new Document();
doc.add(new TextField("contents", "Homer January, Lenny February"));
doc.add(new TextField("title", "2017 on call schedule.xls", Field.Store.YES));

Document doc = new Document();
doc.add(new TextField("contents", "Carl January, Frank February"));
doc.add(new TextField("title", "2018 on call schedule.xls", Field.Store.YES));
</code>```

I can get a hit if I search for the exact title, or for like

```<code>2017
</code>```

but no hits if i try things like

```<code>call
on call
xls
</code>```

I've tried simple things like

```<code> Query query1 = new QueryParser("title", analyzer).parse("on call");
</code>```

and more complicated ideas like

```<code>Builder bb = new BooleanQuery.Builder();
for(String chunk : "on call".split(" ")){
    bb.add(new TermQuery(new Term("title", chunk)), BooleanClause.Occur.SHOULD);
}
BooleanQuery booleanQuery = bb.build();
</code>```

maybe I'm storing my Docs wrong?

I'm using the StandardAnalyzer on search & insert.

Seems like I'm missing something quite fundamental here.. Anyone have any tips please?

答:
I think, its always a good idea to visualize your terms before running your search. Below is image from Luke tool.

That simply indicates that there is no term with schedule but schedule.xls.

I am using Lucene 6.6.6 and had to modify your code to ,

```<code>Document doc = new Document();

        doc.add(new TextField("contents", "Homer January, Lenny February",Store.YES));
        doc.add(new TextField("title", "2017 on call schedule.xls", Store.YES));

        iwriter.addDocument(doc);

        doc = new Document();
        doc.add(new TextField("contents", "Carl January, Frank February",Store.YES));
        doc.add(new TextField("title", "2018 on call schedule.xls", Store.YES));

        iwriter.addDocument(doc);

        iwriter.commit();
</code>```

Now for searching

Your query parser is basically producing a query - title:schedule that means an exact search ( without wild cards ) on field title and since there are no such terms , you find zero hits.

Modifying your query to - Query query1 = new QueryParser("title", analyzer).parse("schedule*"); will get you two hits.

So as a best practice, before searching , always try to have a look & visualize  your indexed data.

ContentLicense: CC BY-SA 3.0

Title: lucene title/content searching

Body:
I'm storing my lucene docs like so:

Document doc = new Document();
doc.add(new TextField("contents", "Homer January, Lenny February"));
doc.add(new TextField("title", "2017 on call schedule.xls", Field.Store.YES));

Document doc = new Document();
doc.add(new TextField("contents", "Carl January, Frank February"));
doc.add(new TextField("title", "2018 on call schedule.xls", Field.Store.YES));

I can get a hit if I search for the exact title, or for like

2017

but no hits if i try things like

call
on call
xls

I've tried simple things like

 Query query1 = new QueryParser("title", analyzer).parse("on call");

and more complicated ideas like

Builder bb = new BooleanQuery.Builder();
for(String chunk : "on call".split(" ")){
    bb.add(new TermQuery(new Term("title", chunk)), BooleanClause.Occur.SHOULD);
}
BooleanQuery booleanQuery = bb.build();

maybe I'm storing my Docs wrong?

I'm using the StandardAnalyzer on search & insert.

Seems like I'm missing something quite fundamental here.. Anyone have any tips please?

Body:
I think, its always a good idea to visualize your terms before running your search. Below is image from Luke tool.

That simply indicates that there is no term with schedule but schedule.xls.

I am using Lucene 6.6.6 and had to modify your code to ,

Document doc = new Document();

        doc.add(new TextField("contents", "Homer January, Lenny February",Store.YES));
        doc.add(new TextField("title", "2017 on call schedule.xls", Store.YES));

        iwriter.addDocument(doc);

        doc = new Document();
        doc.add(new TextField("contents", "Carl January, Frank February",Store.YES));
        doc.add(new TextField("title", "2018 on call schedule.xls", Store.YES));

        iwriter.addDocument(doc);

        iwriter.commit();

Now for searching

Your query parser is basically producing a query - title:schedule that means an exact search ( without wild cards ) on field title and since there are no such terms , you find zero hits.

Modifying your query to - Query query1 = new QueryParser("title", analyzer).parse("schedule*"); will get you two hits.

So as a best practice, before searching , always try to have a look & visualize  your indexed data.


问:
Access Denied Connecting to MySQL with PHP
I know there are a lot of threads asking this question already, but I have been at this for hours and am at wits end.  I am attempting to connect to a MySQL database that I am running of my MacBook with the following PHP:

```<code><?php
DEFINE('DB_USER', 'webuser');
DEFINE('DB_PASSWORD', 'thispassword');
DEFINE('DB_HOST', '127.0.0.1:3306');
DEFINE('DB_NAME', 'learning_accounts');

$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Error connecting: ' .
mysqli_connect_error()
);

?>
</code>```

That returns the following error:

```<code>Error connecting: Access denied for user 'webuser'@'localhost' (using password: YES)
</code>```

I can connect fine through the terminal, even trying to connect with PHP and root does not work.  I am new to both PHP and MySQL so any guidance and insight would be appreciated!

I have tried tons of solutions such as granting privileges, flushing privileges, creating new users, using PDO, nothing has been working - please help!

Thanks so much, I hate learning new languages because then I'm a lost fish when it comes to debugging at first!

Update

I have a password set for my root account, but changing the DB_PASSWORD variable to '' changes the error to: Error connecting: Unknown database 'learning_accounts'

Update 2
I have fixed the issue, check my answer to see how, if you are having this problem then I hope you found this thread quickly!

Zach L

答:
if you tried privilleges, and so on tons of solutions, then you may make another account, and try it.

If same problem occurs, then it is mysql service/daemon problem.

I have same experience before time.

So at that time, I reinstalled mysql server, and problem was fixed.

Body:
I know there are a lot of threads asking this question already, but I have been at this for hours and am at wits end.  I am attempting to connect to a MySQL database that I am running of my MacBook with the following PHP:

<?php
DEFINE('DB_USER', 'webuser');
DEFINE('DB_PASSWORD', 'thispassword');
DEFINE('DB_HOST', '127.0.0.1:3306');
DEFINE('DB_NAME', 'learning_accounts');

$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die('Error connecting: ' .
mysqli_connect_error()
);

?>

That returns the following error:

Error connecting: Access denied for user 'webuser'@'localhost' (using password: YES)

I can connect fine through the terminal, even trying to connect with PHP and root does not work.  I am new to both PHP and MySQL so any guidance and insight would be appreciated!

I have tried tons of solutions such as granting privileges, flushing privileges, creating new users, using PDO, nothing has been working - please help!

Thanks so much, I hate learning new languages because then I'm a lost fish when it comes to debugging at first!

Update

I have a password set for my root account, but changing the DB_PASSWORD variable to '' changes the error to: Error connecting: Unknown database 'learning_accounts'

Update 2
I have fixed the issue, check my answer to see how, if you are having this problem then I hope you found this thread quickly!

Zach L


问:
Is there any way to get only parent terms from custom taxonomy or category?
Is there any way to get only parent terms from custom taxonomy or category?</p>

```<code> $genres = get_the_term_list($post->ID, 'genres', '<div class="genres"><div class="mta">', '', '</div></div>');
</code>```

答:
Try this code,</p>

```<code> <?php $terms = get_terms( array(
        'taxonomy' => 'taxonomy_name',
        'parent'   => 0
    ) );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
        echo '<ul>';
        foreach ( $terms as $term ) {
            echo '<li>' . $term->name . '</li>';
        }
        echo '</ul>';
    } ?>
</code>```

Body:
Is there any way to get only parent terms from custom taxonomy or category?

 $genres = get_the_term_list($post->ID, 'genres', '

', '', '

');

Body:
Try this code,

 <?php $terms = get_terms( array(
        'taxonomy' => 'taxonomy_name',
        'parent'   => 0
    ) );
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
        echo '<ul>';
        foreach ( $terms as $term ) {
            echo '<li>' . $term->name . '</li>';
        }
        echo '</ul>';
    } ?>


问:
how to use connect by method dynamically
How to achieve the following

I've got a query:

```<code>select sr.source_rel_id,
       sr.source_rel_start,
       sr.source_rel_end,
       sr.source_rel_end-sr.source_rel_start+ 1 as daycount
 from (SELECT RELEASES.REL_ID as source_rel_id,
              RELEASES.REL_START_DATE as source_rel_start,
              RELEASES.REL_END_DATE as source_rel_end
         FROM RELEASES) sr
</code>```

which delivers this result:

I'm trying to create an additionally coloumn (based on the attached screenshot) filled with incrementally rising dates between the given start and end interval.

Here's what I want to accomplish:

The number on the right side shows how many records should be generated for each IDs.

Sorry for my poor english, I hope it's understandable.

答:
This is basically a connect-by query that generates rows, for example to generate rows from 1 to 10 use:

```<code>select level as x
from dual connect by level <= 10;

|  X |
|----|
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |
</code>```

in order to generate rows from 5 to 10 use:

```<code>select 5 + level - 1 as x
from dual connect by level <= 10 - 5 + 1;

|  X |
|----|
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |
</code>```

In order to generate dates from 2017-01-02 to 2017-01-05 use:

```<code>select date '2017-01-02' + level - 1 as x
from dual connect by level <= date '2017-01-05' - date '2017-01-02' + 1;

|                    X |
|----------------------|
| 2017-01-02T00:00:00Z |
| 2017-01-03T00:00:00Z |
| 2017-01-04T00:00:00Z |
| 2017-01-05T00:00:00Z |
</code>```

If you are using Oracle 12c then you can use LATERAL or CROSSAPPLY to run the latter generator query form many start+end values coming from source subquery or table, please consider the following example:

```<code>create table probe(
   source_rel_id int,
   source_rel_start date,
   source_rel_end date
);

insert into probe values( 1, date '2017-01-02', date '2017-01-05' );
insert into probe values( 2, date '2017-03-01', date '2017-03-15' );
insert into probe values( 3, date '2017-05-05', date '2017-05-30' );
commit;
</code>```

```<code>select * from probe p
cross apply (
    select p.source_rel_start + level - 1 as my_date
    from dual connect by level <= p.source_rel_end - p.source_rel_start + 1
)

SOURCE_REL_ID SOURCE_REL_START SOURCE_REL_END   MY_DATE
------------- ---------------- ---------------- ----------------
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/02 00:00
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/03 00:00
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/04 00:00
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/05 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/01 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/02 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/03 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/04 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/05 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/06 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/07 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/08 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/09 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/10 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/11 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/12 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/13 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/14 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/15 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/05 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/06 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/07 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/08 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/09 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/10 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/11 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/12 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/13 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/14 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/15 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/16 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/17 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/18 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/19 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/20 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/21 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/22 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/23 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/24 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/25 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/26 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/27 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/28 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/29 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/30 00:00
</code>```

EDIT

What other options I've got, if I'm not having 12c? I should check the
  version but I remember for 11.

Just generate a series of numbers from 1 to N, where N must be greater than the highest count of numbers you want to generate for one record, in this way:

```<code>  SELECT level as xyz FROM dual
  CONNECT BY LEVEL <= 10000
</code>```

and then join a result of the above query to the table in this way --> please see this demo

```<code>SELECT source_rel_id, source_rel_start, source_rel_end,
       source_rel_start + xyz - 1 As days
FROM (
  SELECT level as xyz FROM dual
  CONNECT BY LEVEL <= 10000
) x
JOIN probe p
ON xyz <= source_rel_end - source_rel_start + 1
ORDER BY source_rel_id, days

| SOURCE_REL_ID |     SOURCE_REL_START |       SOURCE_REL_END |                 DAYS |
|---------------|----------------------|----------------------|----------------------|
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-02T00:00:00Z |
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-03T00:00:00Z |
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-04T00:00:00Z |
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-05T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-01T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-02T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-03T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-04T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-05T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-06T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-07T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-08T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-09T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-10T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-11T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-12T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-13T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-14T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-15T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-05T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-06T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-07T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-08T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-09T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-10T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-11T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-12T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-13T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-14T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-15T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-16T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-17T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-18T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-19T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-20T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-21T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-22T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-23T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-24T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-25T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-26T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-27T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-28T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-29T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-30T00:00:00Z |
</code>```

I've used 10000, it should be enough since 10000 days is over 27 years, so I don't think you need to generate 27 years of dates for each record, but if this is still too little, then in practice it can be a number somwhere between 1 million and 10 millions. Since rows are generated in the memory, at some point ( 1~10 millions) you will hit an out of memory error.

You can also use a subquery to calculate this limit exactly:

```<code>SELECT level as xyz FROM dual
CONNECT BY LEVEL <= (
     SELECT max(  source_rel_end - source_rel_start ) + 1
     FROM probe
)
</code>```

Body:
How to achieve the following

I've got a query:

select sr.source_rel_id,
       sr.source_rel_start,
       sr.source_rel_end,
       sr.source_rel_end-sr.source_rel_start+ 1 as daycount
 from (SELECT RELEASES.REL_ID as source_rel_id,
              RELEASES.REL_START_DATE as source_rel_start,
              RELEASES.REL_END_DATE as source_rel_end
         FROM RELEASES) sr

which delivers this result:

I'm trying to create an additionally coloumn (based on the attached screenshot) filled with incrementally rising dates between the given start and end interval.

Here's what I want to accomplish:

The number on the right side shows how many records should be generated for each IDs.

Sorry for my poor english, I hope it's understandable.

Body:
This is basically a connect-by query that generates rows, for example to generate rows from 1 to 10 use:

select level as x
from dual connect by level <= 10;

|  X |
|----|
|  1 |
|  2 |
|  3 |
|  4 |
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |

in order to generate rows from 5 to 10 use:

select 5 + level - 1 as x
from dual connect by level <= 10 - 5 + 1;

|  X |
|----|
|  5 |
|  6 |
|  7 |
|  8 |
|  9 |
| 10 |

In order to generate dates from 2017-01-02 to 2017-01-05 use:

select date '2017-01-02' + level - 1 as x
from dual connect by level <= date '2017-01-05' - date '2017-01-02' + 1;

|                    X |
|----------------------|
| 2017-01-02T00:00:00Z |
| 2017-01-03T00:00:00Z |
| 2017-01-04T00:00:00Z |
| 2017-01-05T00:00:00Z |

If you are using Oracle 12c then you can use LATERAL or CROSSAPPLY to run the latter generator query form many start+end values coming from source subquery or table, please consider the following example:

create table probe(
   source_rel_id int,
   source_rel_start date,
   source_rel_end date
);

insert into probe values( 1, date '2017-01-02', date '2017-01-05' );
insert into probe values( 2, date '2017-03-01', date '2017-03-15' );
insert into probe values( 3, date '2017-05-05', date '2017-05-30' );
commit;

select * from probe p
cross apply (
    select p.source_rel_start + level - 1 as my_date
    from dual connect by level <= p.source_rel_end - p.source_rel_start + 1
)

SOURCE_REL_ID SOURCE_REL_START SOURCE_REL_END   MY_DATE
------------- ---------------- ---------------- ----------------
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/02 00:00
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/03 00:00
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/04 00:00
            1 2017/01/02 00:00 2017/01/05 00:00 2017/01/05 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/01 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/02 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/03 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/04 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/05 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/06 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/07 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/08 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/09 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/10 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/11 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/12 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/13 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/14 00:00
            2 2017/03/01 00:00 2017/03/15 00:00 2017/03/15 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/05 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/06 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/07 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/08 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/09 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/10 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/11 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/12 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/13 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/14 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/15 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/16 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/17 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/18 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/19 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/20 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/21 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/22 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/23 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/24 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/25 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/26 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/27 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/28 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/29 00:00
            3 2017/05/05 00:00 2017/05/30 00:00 2017/05/30 00:00

EDIT

What other options I've got, if I'm not having 12c? I should check the
  version but I remember for 11.

Just generate a series of numbers from 1 to N, where N must be greater than the highest count of numbers you want to generate for one record, in this way:

  SELECT level as xyz FROM dual
  CONNECT BY LEVEL <= 10000

and then join a result of the above query to the table in this way --> please see this demo

SELECT source_rel_id, source_rel_start, source_rel_end,
       source_rel_start + xyz - 1 As days
FROM (
  SELECT level as xyz FROM dual
  CONNECT BY LEVEL <= 10000
) x
JOIN probe p
ON xyz <= source_rel_end - source_rel_start + 1
ORDER BY source_rel_id, days

| SOURCE_REL_ID |     SOURCE_REL_START |       SOURCE_REL_END |                 DAYS |
|---------------|----------------------|----------------------|----------------------|
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-02T00:00:00Z |
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-03T00:00:00Z |
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-04T00:00:00Z |
|             1 | 2017-01-02T00:00:00Z | 2017-01-05T00:00:00Z | 2017-01-05T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-01T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-02T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-03T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-04T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-05T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-06T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-07T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-08T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-09T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-10T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-11T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-12T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-13T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-14T00:00:00Z |
|             2 | 2017-03-01T00:00:00Z | 2017-03-15T00:00:00Z | 2017-03-15T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-05T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-06T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-07T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-08T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-09T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-10T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-11T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-12T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-13T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-14T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-15T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-16T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-17T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-18T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-19T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-20T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-21T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-22T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-23T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-24T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-25T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-26T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-27T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-28T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-29T00:00:00Z |
|             3 | 2017-05-05T00:00:00Z | 2017-05-30T00:00:00Z | 2017-05-30T00:00:00Z |

I've used 10000, it should be enough since 10000 days is over 27 years, so I don't think you need to generate 27 years of dates for each record, but if this is still too little, then in practice it can be a number somwhere between 1 million and 10 millions. Since rows are generated in the memory, at some point ( 1~10 millions) you will hit an out of memory error.

You can also use a subquery to calculate this limit exactly:

SELECT level as xyz FROM dual
CONNECT BY LEVEL <= (
     SELECT max(  source_rel_end - source_rel_start ) + 1
     FROM probe
)


问:
No provider for NavController! Ionic 3
I'm Using Ionic3 for my university project , I had added setting parts of my app.html and trying to link (click)="home()" but it's not working for me.

I got following error

Error: No provider for NavController!
      at injectionError (http://localhost:8100/build/vendor.js:1527:90)
      at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
      at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
      at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
      at ReflectiveInjector.getByKey (http://localhost:8100/build/vendor.js:2978:25)
      at ReflectiveInjector.get (http://localhost:8100/build/vendor.js:2847:21)
      at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
      at NgModuleRef_.get (http://localhost:8100/build/vendor.js:10935:16)
      at resolveDep (http://localhost:8100/build/vendor.js:11438:45)
      at createClass (http://localhost:8100/build/vendor.js:11302:32)

app.html

```<code><!--------------------------------------Main Navigation--------------------------->

<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
  <ion-header>
    <ion-toolbar>
      <ion-grid>

        <ion-row>
          <ion-col col-6>
            <div text-left style="" class="app-listname">
              Project</div>
          </ion-col>
          <ion-col  (click)="home()">
            <div class="tether-setting" style="text-align: right;font-size: 2rem; color:#a57958;">
              <ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>
            </div>

          </ion-col>
          <ion-col>
            <div class="tether-logout" style="font-size: 2rem; color:#a57958; text-indent: 0rem;  text-align: right;">
              <ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>
            </div>
          </ion-col>
        </ion-row>
      </ion-grid>

    </ion-toolbar>
  </ion-header>

  <ion-content>
    <div class="ion-tm">
      <ion-list>
        <button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
          <ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>

      </ion-list>
    </div>
  </ion-content>

</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>
<!--------------------------------------Main Navigation--------------------------->
</code>```

app.component.ts

```<code>   import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import {HomePage} from '../pages/home/home';

import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";

import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = UserloginPage;
  selectedTheme: String;  //Themeoption
  activepage: any;
  pages: Array<{ title: string, component: any, icon: string }>;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
    this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val);  //Themeoption

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    this.pages = [

      {title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},

      {title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
      {title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
      {title: '  User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},

    ];

    this.activepage = this.pages[0];
  }

  //Themeoption
  openPage(page) {

    this.nav.setRoot(page.component);
    this.activepage = page;

  }
  checkActive(page) {
    return page == this.activepage;
  }

  home(){
    this.navCtrl.push(HomePage);
  }
}
</code>```

答:
Well, why do you try to import NavController? You have   @ViewChild(Nav) nav: Nav; you can use it.

You must remove NavController from injecting in your constructor

Replace your line

```<code>constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
</code>```

with

```<code>constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider) {
</code>```

Then replace the line

```<code> this.navCtrl.push(HomePage);
</code>```

with

```<code> this.nav.push(HomePage);
</code>```

Title: No provider for NavController! Ionic 3

Body:
I'm Using Ionic3 for my university project , I had added setting parts of my app.html and trying to link (click)="home()" but it's not working for me.

I got following error

Error: No provider for NavController!
      at injectionError (http://localhost:8100/build/vendor.js:1527:90)
      at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
      at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
      at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
      at ReflectiveInjector.getByKey (http://localhost:8100/build/vendor.js:2978:25)
      at ReflectiveInjector.get (http://localhost:8100/build/vendor.js:2847:21)
      at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
      at NgModuleRef_.get (http://localhost:8100/build/vendor.js:10935:16)
      at resolveDep (http://localhost:8100/build/vendor.js:11438:45)
      at createClass (http://localhost:8100/build/vendor.js:11302:32)

app.html

<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
  <ion-header>
    <ion-toolbar>
      <ion-grid>

        <ion-row>
          <ion-col col-6>

              Project

          </ion-col>
          <ion-col  (click)="home()">

              <ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>

          </ion-col>
          <ion-col>

              <ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>

          </ion-col>
        </ion-row>
      </ion-grid>

    </ion-toolbar>
  </ion-header>

  <ion-content>

      <ion-list>
        <button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
          <ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>

      </ion-list>

  </ion-content>

</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>

app.component.ts

   import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import {HomePage} from '../pages/home/home';

import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";

import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = UserloginPage;
  selectedTheme: String;  //Themeoption
  activepage: any;
  pages: Array<{ title: string, component: any, icon: string }>;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
    this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val);  //Themeoption

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    this.pages = [

      {title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},

      {title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
      {title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
      {title: '  User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},

    ];

    this.activepage = this.pages[0];
  }

  //Themeoption
  openPage(page) {

    this.nav.setRoot(page.component);
    this.activepage = page;

  }
  checkActive(page) {
    return page == this.activepage;
  }

  home(){
    this.navCtrl.push(HomePage);
  }
}

Body:
Well, why do you try to import NavController? You have   @ViewChild(Nav) nav: Nav; you can use it.

You must remove NavController from injecting in your constructor

Replace your line

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {

with

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider) {

Then replace the line

 this.navCtrl.push(HomePage);

with

 this.nav.push(HomePage);

ContentLicense: CC BY-SA 4.0


问:
SQL query using Like and Between in the same statement
so here is my problem I need to select records in between year 2000-2008 but the columns I need to search for is in type varchar example:

```<code>IntRecordID     VARCHARYear
    1            1990-2000
    2            2001-2005
    3            2005-2006
    4            2007-2008
    5            2009-2020
</code>```

select all record id that has VARCHARYear between 2000 and 2008

```<code>IntRecordID
    2
    3
    4
</code>```

what is the sql query that I need to achieve this?

答:
Hope your VARCHARYear field always be inn YYYY-YYYY format.

```<code>SELECT  *
FROM    table_name
WHERE   LEFT(VARCHARYear,4)     >   2000
    AND RIGHT(VARCHARYear,4)    <=  2008
</code>```

Body:
so here is my problem I need to select records in between year 2000-2008 but the columns I need to search for is in type varchar example:

IntRecordID     VARCHARYear
    1            1990-2000
    2            2001-2005
    3            2005-2006
    4            2007-2008
    5            2009-2020

select all record id that has VARCHARYear between 2000 and 2008

IntRecordID
    2
    3
    4

what is the sql query that I need to achieve this?

Body:
Hope your VARCHARYear field always be inn YYYY-YYYY format.

SELECT  *
FROM    table_name
WHERE   LEFT(VARCHARYear,4)     >   2000
    AND RIGHT(VARCHARYear,4)    <=  2008


问:
Smart CVS connection reset error on Windows 7
I have used SmartCVS under Windows XP and Vista several years and it works fine, but after upgrading to Windows 7 it doesn't work.

Following error message is present in the SmartCVS log file:

```<code>[WorkerThread-1] ERROR javacvs.requestprocessor  -
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
</code>```

The error occurs during any operation (commit, update, compare, etc.).
I have tried to with Windows Firewall disabled, but still get this error.
After the error internet connection is gone at all, and I have to reboot the PC to have internet access.

Is there anybody who have the same problem?
Any help will useful.

Thanks

答: It looks like a low-level TCP error. Try to update your network driver.</p>

Body:
I have used SmartCVS under Windows XP and Vista several years and it works fine, but after upgrading to Windows 7 it doesn't work.

Following error message is present in the SmartCVS log file:

[WorkerThread-1] ERROR javacvs.requestprocessor  -
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)

The error occurs during any operation (commit, update, compare, etc.).
I have tried to with Windows Firewall disabled, but still get this error.
After the error internet connection is gone at all, and I have to reboot the PC to have internet access.

Is there anybody who have the same problem?
Any help will useful.

Thanks


问:
Prevent Intellisense from inserting semicolons in VS Code
We don't use semicolons in TypeScript. Each time Intellisense in VS code (v1.18.1) inserts a line, it terminates it with ;. Example would be an import statement.

Is it possible to configure VS Code not to append semicolons? Very inefficient right now to have to delete them manually.

答:
TSLint semicolon rule (has autofix)

TSLint extension for vscode

tslint.json rules section:

"semicolon": [true, "never"]
```

<p>settings.json <kbd>Ctrl</kbd>+<kbd>,</kbd></p>

<pre class="lang-json prettyprint-override"><code>"tslint.autoFixOnSave": ["semicolon"]
</code>```

There is an open issue about it https://github.com/Microsoft/TypeScript/issues/19882

Body:
TSLint semicolon rule (has autofix)

TSLint extension for vscode

tslint.json rules section:

"semicolon": [true, "never"]

settings.json Ctrl+,

"tslint.autoFixOnSave": ["semicolon"]

There is an open issue about it https://github.com/Microsoft/TypeScript/issues/19882


问:
Dockerizing a Web Application
I am new to this Containerization and I was wondering how Docker could replace Virtual machines?

I am given a case study in which there are 2 virtual machines each acting as a virtual server, one is a Development server and the other is a Test Server and I am asked to study how Docker could help in managing the workflow efficiently.

In this case the 2 virtual Machines are Servers and the idea of Docker replacing virtual machines is confusing me.

can anyone help me understand this concept.

Thanks in Advance!!

答:
I am not sure how a server can be completely replaced by a docker container, so I am assuming you want to replace an 2 applications running in 2 servers into 1 server running 2 containers of each test and dev apps.

I am going to make a few assumptions before I can answer.

First I am going to assume, your application is a simple web service that has been deployed on a tomcat/IBM websphere in the server.

Secondly, I am assuming the databases are on a different server for both test and dev servers.

Docker Basics

Dockerfile  - USing the command docker build, you can create an image

Docker Image - This is created from a dockerfile

Docker Container - When you do a docker run of an image, a container gets created. A running instance of an image is your container

Docker Registry - The place from where you can download base images
So here it goes,

Setup docker on a unix server.

Now you need to create 2 containers which will host identical apps. For this, you first need to write a dockerfile, create an image and then start the container using the image.

A sample dockerfile would look like something below

```<code>FROM webspher-liberty17:webProfile7

ENV SERVER_NAME=myapptestserver

RUN ["/bin/bash", "-c", "/opt/ibm/wlp/bin/server create $SERVER_NAME"]

EXPOSE 9080 9443

COPY server.xml jvm.options /opt/ibm/wlp/usr/servers/$SERVER_NAME/
COPY *.war /opt/ibm/wlp/usr/servers/$SERVER_NAME/dropins/

CMD ["/opt/ibm/docker/docker-server", "run", "myapptestserver"]
</code>```

Now when you do a docker build of this docker file, it would create an image with base layer as ibm liberty. Every command after the FROM allows you to add an additional layer, so you can customize to your specifics.

Once you have done the above for both your apps, you practically have two variants of your app running on same server but serving two different environments.

Best part, add this to your CI/CD pipeline in bamboo/jenkins, and you can bring up and down environments in a jiffy.

Title: Dockerizing a Web Application

Body:
I am not sure how a server can be completely replaced by a docker container, so I am assuming you want to replace an 2 applications running in 2 servers into 1 server running 2 containers of each test and dev apps.

I am going to make a few assumptions before I can answer.

First I am going to assume, your application is a simple web service that has been deployed on a tomcat/IBM websphere in the server.

Secondly, I am assuming the databases are on a different server for both test and dev servers.

Docker Basics

Dockerfile  - USing the command docker build, you can create an image

Docker Image - This is created from a dockerfile

Docker Container - When you do a docker run of an image, a container gets created. A running instance of an image is your container

Docker Registry - The place from where you can download base images
So here it goes,

Setup docker on a unix server.

Now you need to create 2 containers which will host identical apps. For this, you first need to write a dockerfile, create an image and then start the container using the image.

A sample dockerfile would look like something below

FROM webspher-liberty17:webProfile7

ENV SERVER_NAME=myapptestserver

RUN ["/bin/bash", "-c", "/opt/ibm/wlp/bin/server create $SERVER_NAME"]

EXPOSE 9080 9443

COPY server.xml jvm.options /opt/ibm/wlp/usr/servers/$SERVER_NAME/
COPY *.war /opt/ibm/wlp/usr/servers/$SERVER_NAME/dropins/

CMD ["/opt/ibm/docker/docker-server", "run", "myapptestserver"]

Now when you do a docker build of this docker file, it would create an image with base layer as ibm liberty. Every command after the FROM allows you to add an additional layer, so you can customize to your specifics.

Once you have done the above for both your apps, you practically have two variants of your app running on same server but serving two different environments.

Best part, add this to your CI/CD pipeline in bamboo/jenkins, and you can bring up and down environments in a jiffy.


问:
Read content image and store it into a file with `PHP` and `CURL` and executable commands
I have a dynamic image as PHP file:

```<code><?php
header('Content-type: image/png');
echo file_get_contents('image.png');
</code>```

Now I want to read content image and store it into a file with PHP and CURL and executable commands.

First for sure, I test this command in cmd:

```<code># curl -s http://localhost/image.php > output.png
</code>```

This works good.

Now I use of same command in the php code with shell_exec function:

```<code><?php
$cmd = 'curl -s http://localhost/image.php';
$out = shell_exec($cmd);
file_put_contents('output.png', $out);
</code>```

But the output incomplete:

```<code>‰PNG
</code>```

And this may be binary in the photo because of NULL characters.

Another test I try with exec function.

```<code><?php
$cmd = 'curl -s http://localhost/image.php';
exec($cmd, $out);
file_put_contents('output.png', $out);
</code>```

Seem the output file contain real binary image:

```<code>‰PNG
IHDR   ً   P   Z'ï      PLTEےےے   –––¹¸vٍ       pHYs  ؤ  ؤ•+  tIDATX…¥کQ®©„Mdٍl"ْ®"کgˆ`ض“Hة{"e61«¼_u–0™(sخك
کr¹\يكےًا~¶’¼ïk¥‘’¥½ZKأb¬Zkّ‰¶»¯½|إj–|ظ.nضـ²¯آ‡y*üµàٌب›g–Z²'¹چضِê¶طج£µث5³kjںىkoُ
</code>```

But the image will not be shown.

I diff real image and new generated image:

Apparently, because the content of the $out is an array. Not well written in the new file.

Now, Where are my forms of work and how can I get to my goal?

EDIT: seem this problem is just on windows.

答:
exec tries to explode lines and returns an array that is hard to deal with

shell_exec will work just fine.

```<code><?php
    $cmd = 'curl -s http://localhost/image.php';
    $out = shell_exec($cmd);
    file_put_contents('output.png', $out);
</code>```

Body:
I have a dynamic image as PHP file:

<?php
header('Content-type: image/png');
echo file_get_contents('image.png');

Now I want to read content image and store it into a file with PHP and CURL and executable commands.

First for sure, I test this command in cmd:

# curl -s http://localhost/image.php > output.png

This works good.

Now I use of same command in the php code with shell_exec function:

<?php
$cmd = 'curl -s http://localhost/image.php';
$out = shell_exec($cmd);
file_put_contents('output.png', $out);

But the output incomplete:

‰PNG

And this may be binary in the photo because of NULL characters.

Another test I try with exec function.

<?php
$cmd = 'curl -s http://localhost/image.php';
exec($cmd, $out);
file_put_contents('output.png', $out);

Seem the output file contain real binary image:

‰PNG
IHDR   ً   P   Z'ï      PLTEےےے   –––¹¸vٍ       pHYs  ؤ  ؤ•+  tIDATX…¥کQ®©„Mdٍl"ْ®"کgˆ`ض“Hة{"e61«¼_u–0™(sخك
کr¹\يكےًا~¶’¼ïk¥‘’¥½ZKأb¬Zkّ‰¶»¯½|إj–|ظ.nضـ²¯آ‡y*üµàٌب›g–Z²'¹چضِê¶طج£µث5³kjںىkoُ

But the image will not be shown.

I diff real image and new generated image:

Apparently, because the content of the $out is an array. Not well written in the new file.

Now, Where are my forms of work and how can I get to my goal?

EDIT: seem this problem is just on windows.

Body:
exec tries to explode lines and returns an array that is hard to deal with

shell_exec will work just fine.

<?php
    $cmd = 'curl -s http://localhost/image.php';
    $out = shell_exec($cmd);
    file_put_contents('output.png', $out);


问:
Native C Websocket Client
I have been playing around with writing some code from some lightweight clients and was wondering if there was any good lightweight websocket client that allows connection to secure websockets (wss) for C applications.

Some example code would be great if it existed as well as I am coming from a OOP background which makes it a bit trickey

答:
I'm told libwebsockets can be used as a client as well.

The facil.io has a simple client (no SSL/TLS)... but you could probably roll your own with facil.io's parser / formater.

You could also use the library's read/write hooks to handle TLS/SSL connections, but you'll have to manage handshakes, since it's HTTP and Websocket implementations are server oriented (though the HTTP/1.1 parser supports client side parsing as well).

Title: Native C Websocket Client


问:
Reading in data from a txt file to a vector of structs in c++
I am trying to read data from a file in which the data is semicolon delimited. Example:

The Lord of the Rings: The Fellowship of the Ring;Jackson, Peter;2001;178;93000000;871530324

Above is all one entry. There is also a number in the first line of the file stating the number of entries. Each entry is on a different line. I am trying to read in this data to a vector of structs called info. The struct is named MovieData.

```<code>vector<MovieData> readFile(string fName,MovieData info, int& numOfMovies){
    vector<MovieData> movies;
    ifstream fin;
    fin.open(fName);

    fin >> numOfMovies;
    cout << "Number of Movies: " << numOfMovies << "\n";

    for(int i=0;i<numOfMovies;i++){
        getline(fin, info.Title, ';');
        getline(fin,info.Dir, ';');
        getline(fin,info.year, ';');
        getline(fin,info.time, ';');
        getline(fin,info.cost, ';');
        getline(fin, info.revenue);
        info.profit = info.revenue - info.cost;
        movies.push_back(info);
    }

    return movies;
}
</code>```

I am having trouble with reading in the data from the file using getline(), but I believe I have everything else correct.

答:
I Figured it out. Changed some stuff and got everything to work. Thanks for your help.</p>

```<code>vector<MovieData> readFile(string fName, struct MovieData, int& numOfMovies){
    vector<MovieData> movies;
    ifstream fin;
    fin.open(fName);

    fin >> numOfMovies;
    cout << "Number of Movies: " << numOfMovies << "\n";

    for(int i=0;i<numOfMovies;i++){
        movies.push_back(MovieData());
        getline(fin, movies[i].Title, ';');
        getline(fin,movies[i].Dir, ';');
        fin >> movies[i].year;
        fin.ignore();
        fin >> movies[i].time;
        fin.ignore();
        fin >> movies[i].cost;
        fin.ignore();
        fin >> movies[i].revenue;
        fin.ignore();
        fin >> movies[i].profit;
        movies[i].profit = movies[i].revenue - movies[i].cost;

    }

    return movies;
}
</code>```

Body:
I am trying to read data from a file in which the data is semicolon delimited. Example:

The Lord of the Rings: The Fellowship of the Ring;Jackson, Peter;2001;178;93000000;871530324

Above is all one entry. There is also a number in the first line of the file stating the number of entries. Each entry is on a different line. I am trying to read in this data to a vector of structs called info. The struct is named MovieData.

vector<MovieData> readFile(string fName,MovieData info, int& numOfMovies){
    vector<MovieData> movies;
    ifstream fin;
    fin.open(fName);

    fin >> numOfMovies;
    cout << "Number of Movies: " << numOfMovies << "\n";

    for(int i=0;i<numOfMovies;i++){
        getline(fin, info.Title, ';');
        getline(fin,info.Dir, ';');
        getline(fin,info.year, ';');
        getline(fin,info.time, ';');
        getline(fin,info.cost, ';');
        getline(fin, info.revenue);
        info.profit = info.revenue - info.cost;
        movies.push_back(info);
    }

    return movies;
}

I am having trouble with reading in the data from the file using getline(), but I believe I have everything else correct.

Body:
I Figured it out. Changed some stuff and got everything to work. Thanks for your help.

vector<MovieData> readFile(string fName, struct MovieData, int& numOfMovies){
    vector<MovieData> movies;
    ifstream fin;
    fin.open(fName);

    fin >> numOfMovies;
    cout << "Number of Movies: " << numOfMovies << "\n";

    for(int i=0;i<numOfMovies;i++){
        movies.push_back(MovieData());
        getline(fin, movies[i].Title, ';');
        getline(fin,movies[i].Dir, ';');
        fin >> movies[i].year;
        fin.ignore();
        fin >> movies[i].time;
        fin.ignore();
        fin >> movies[i].cost;
        fin.ignore();
        fin >> movies[i].revenue;
        fin.ignore();
        fin >> movies[i].profit;
        movies[i].profit = movies[i].revenue - movies[i].cost;

    }

    return movies;
}


问:
F# Compiler Service: get a list of names visible in the scope
How can I get get a list of names visible in the scope with FSC?
I tried this:

```<code>#r "../../packages/FSharp.Compiler.Service.16.0.2/lib/net45/FSharp.Compiler.Service.dll"
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.SourceCodeServices

do
    let file = "TestFileName.fsx"
    let checker = SourceCodeServices.FSharpChecker.Create()

    let code =
        """
let testStr = "x"
t
"""
    async{
        let! options, _ = checker.GetProjectOptionsFromScript(file,code)
        let! parseRes,checkAnser = checker.ParseAndCheckFileInProject(file, 0, code, options)
        match checkAnser with
        | FSharpCheckFileAnswer.Succeeded checkRes ->
            let! decls =
                checkRes.GetDeclarationListInfo(
                    Some parseRes,  //ParsedFileResultsOpt
                    3 ,              //line
                    1 ,              //colAtEndOfPartialName
                    "t" ,            //lineText
                    [ "t" ] ,        //qualifyingNames
                    "" ,             //partialName
                    ( fun _ -> [] )  //getAllSymbols: (unit -> AssemblySymbol list)
                    )

            if Seq.isEmpty decls.Items then
                printfn "*no declarations found*"
            else
                decls.Items
                |> Seq.sortBy (fun d -> d.Name)
                |> Seq.truncate 10
                |> Seq.iter (fun d -> printfn "decl: %s" d.Name)

        | _ -> failwithf "*Parsing did not finish... "
        } |> Async.RunSynchronously
</code>```

but it only prints "no declarations found". I would expect not only testStr but also all the other names that are available by default.
I did not find an example in the documentation.

答: qualifyingNames should be an empty list, it’s for dot separated prefix, excluding the last (possibly partial) ident. However, there is no a method in FCS that returns unfiltered list of names for scope, yet it’s really easy to add one.

Body:
How can I get get a list of names visible in the scope with FSC?
I tried this:

#r "../../packages/FSharp.Compiler.Service.16.0.2/lib/net45/FSharp.Compiler.Service.dll"
open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.SourceCodeServices

do
    let file = "TestFileName.fsx"
    let checker = SourceCodeServices.FSharpChecker.Create()

    let code =
        """
let testStr = "x"
t
"""
    async{
        let! options, _ = checker.GetProjectOptionsFromScript(file,code)
        let! parseRes,checkAnser = checker.ParseAndCheckFileInProject(file, 0, code, options)
        match checkAnser with
        | FSharpCheckFileAnswer.Succeeded checkRes ->
            let! decls =
                checkRes.GetDeclarationListInfo(
                    Some parseRes,  //ParsedFileResultsOpt
                    3 ,              //line
                    1 ,              //colAtEndOfPartialName
                    "t" ,            //lineText
                    [ "t" ] ,        //qualifyingNames
                    "" ,             //partialName
                    ( fun _ -> [] )  //getAllSymbols: (unit -> AssemblySymbol list)
                    )

            if Seq.isEmpty decls.Items then
                printfn "*no declarations found*"
            else
                decls.Items
                |> Seq.sortBy (fun d -> d.Name)
                |> Seq.truncate 10
                |> Seq.iter (fun d -> printfn "decl: %s" d.Name)

        | _ -> failwithf "*Parsing did not finish... "
        } |> Async.RunSynchronously

but it only prints "no declarations found". I would expect not only testStr but also all the other names that are available by default.
I did not find an example in the documentation.


问:
Postgresql: How to use a WITH subquery with JOIN
I have 2 tables: orders and contragents. Each contragent might have many orders. Each order has an order_date. I want to get a first order date for each contragent, but with a caveat: if there was a gap between orders more than 180 days, I need to "forget" those before the gap (and thus the first order after the gap is considered "the first".

For this, I've implement a following statement:

```<code>with o1 as (
    select order_date, lag(order_date) over(order by order_date ASC) as prev_order_date
    from orders o
    where o.contragent_code = :code
    order by order_date desc)
select o1.date_debts from o1
where extract(day from o1.order_date-o1.prev_order_date)>=180 or o1.prev_order_date is null
order by order_date desc
limit 1
</code>```

this results in a single value being returned for a contragent with code code, which is what I need.

But I cannot figure out how to run a select that would return this date for every contragent in a table!

The only way I was able to do it was using a CREATE FUNCTION, but I will be unable to do it on production, so.. any advice is highly appreciated!

答:
You want to add partition by, which is kinda like group by for over.

```<code>with o1 as (
    select order_date, lag(order_date) over(partition by contragent_code order by order_date ASC) as prev_order_date
    from orders o
    order by order_date desc)
select o1.date_debts from o1
where extract(day from o1.order_date-o1.prev_order_date)>=180 or o1.prev_order_date is null
order by order_date desc
</code>```

Now lag looks for the previous order_date of rows with same contragent_code.

UPDATE: at the end, it appears that that was not exactly enough. This is the final statement:

```<code>with s as (
    select o.contragent_code, o.order_date,
        case
        when
            extract(day from order_date-lag(order_date) over(partition by contragent_code order by order_date asc))>=180
        then o.order_date else null
        end as date_with_gap
    from orders o
) select contragent_code, coalesce(max(date_with_gap), min(order_date)) from s
group by contragent_code
</code>```

Body:
I have 2 tables: orders and contragents. Each contragent might have many orders. Each order has an order_date. I want to get a first order date for each contragent, but with a caveat: if there was a gap between orders more than 180 days, I need to "forget" those before the gap (and thus the first order after the gap is considered "the first".

For this, I've implement a following statement:

with o1 as (
    select order_date, lag(order_date) over(order by order_date ASC) as prev_order_date
    from orders o
    where o.contragent_code = :code
    order by order_date desc)
select o1.date_debts from o1
where extract(day from o1.order_date-o1.prev_order_date)>=180 or o1.prev_order_date is null
order by order_date desc
limit 1

this results in a single value being returned for a contragent with code code, which is what I need.

But I cannot figure out how to run a select that would return this date for every contragent in a table!

The only way I was able to do it was using a CREATE FUNCTION, but I will be unable to do it on production, so.. any advice is highly appreciated!

Body:
You want to add partition by, which is kinda like group by for over.

with o1 as (
    select order_date, lag(order_date) over(partition by contragent_code order by order_date ASC) as prev_order_date
    from orders o
    order by order_date desc)
select o1.date_debts from o1
where extract(day from o1.order_date-o1.prev_order_date)>=180 or o1.prev_order_date is null
order by order_date desc

Now lag looks for the previous order_date of rows with same contragent_code.

UPDATE: at the end, it appears that that was not exactly enough. This is the final statement:

with s as (
    select o.contragent_code, o.order_date,
        case
        when
            extract(day from order_date-lag(order_date) over(partition by contragent_code order by order_date asc))>=180
        then o.order_date else null
        end as date_with_gap
    from orders o
) select contragent_code, coalesce(max(date_with_gap), min(order_date)) from s
group by contragent_code


问:
Need help to extract a data with Label using XSLT
```<code><ws:Address_Line_Data ws:PriorValue="" ws:Label="Address Line 1" ws:Type="ADDRESS_LINE_1">8925 Lietner lWay</ws:Address_Line_Data>
<ws:Address_Line_Data ws:PriorValue="" ws:Label="Address Line " ws:Type="ADDRESS_LINE_2">#504</ws:Address_Line_Data>
</code>```

I have two feed for the address. I need the value only with "label Address Line 1" also I need to normalize the space.

答:
You can try</p>

```<code><xsl:value-of select="*[normalize-space(@ws:Label) = 'Address Line 1']"/>
</code>```

Body:
<ws:Address_Line_Data ws:PriorValue="" ws:Label="Address Line 1" ws:Type="ADDRESS_LINE_1">8925 Lietner lWay</ws:Address_Line_Data>
<ws:Address_Line_Data ws:PriorValue="" ws:Label="Address Line " ws:Type="ADDRESS_LINE_2">#504</ws:Address_Line_Data>

I have two feed for the address. I need the value only with "label Address Line 1" also I need to normalize the space.

Body:
You can try

<xsl:value-of select="*[normalize-space(@ws:Label) = 'Address Line 1']"/>


问:
How read .mat openmodelica result file in python correctly?
I tried to read modelica resul file (.mat) in python and used code like this:

```<code>data = scipy.io.loadmat('TPPSim.Boilers.Tests.EMA_028_HRSG_Test_res.mat')
print data.keys()
['Aclass', 'dataInfo', 'name', 'data_2', 'data_1', 'description']

names = [''.join(s).rstrip() for s in zip(*data['name'])]
len(names)
899
</code>```

But it's not all variables that i can see in 'OMEdit plotting'. I think that's only variables that have derivatives in simulation.

And data['data_1'] have more than 899 sets of data:

```<code>data['data_2'][0]
4192L
</code>```

How I can get all results in Python?

Sorry for my bad English.

Artyom.

答:
You could use a Python library that handles the format, such as DyMat</p>

```<code>d = DyMat.DyMatFile('TPPSim.Boilers.Tests.EMA_028_HRSG_Test_res.mat')
print(d.names())
</code>```

Body:
I tried to read modelica resul file (.mat) in python and used code like this:

data = scipy.io.loadmat('TPPSim.Boilers.Tests.EMA_028_HRSG_Test_res.mat')
print data.keys()
['Aclass', 'dataInfo', 'name', 'data_2', 'data_1', 'description']

names = [''.join(s).rstrip() for s in zip(*data['name'])]
len(names)
899

But it's not all variables that i can see in 'OMEdit plotting'. I think that's only variables that have derivatives in simulation.

And data['data_1'] have more than 899 sets of data:

data['data_2'][0]
4192L

How I can get all results in Python?

Sorry for my bad English.

Artyom.

Body:
You could use a Python library that handles the format, such as DyMat

d = DyMat.DyMatFile('TPPSim.Boilers.Tests.EMA_028_HRSG_Test_res.mat')
print(d.names())


问:
Why is it impossible, without attempting I/O, to detect that TCP socket was gracefully closed by peer?
As a follow up to a recent question, I wonder why it is impossible in Java, without attempting reading/writing on a TCP socket, to detect that the socket has been gracefully closed by the peer? This seems to be the case regardless of whether one uses the pre-NIO Socket or the NIO SocketChannel.

When a peer gracefully closes a TCP connection, the TCP stacks on both sides of the connection know about the fact. The server-side (the one that initiates the shutdown) ends up in state FIN_WAIT2, whereas the client-side (the one that does not explicitly respond to the shutdown) ends up in state CLOSE_WAIT. Why isn't there a method in Socket or SocketChannel that can query the TCP stack to see whether the underlying TCP connection has been terminated? Is it that the TCP stack doesn't provide such status information? Or is it a design decision to avoid a costly call into the kernel?

With the help of the users who have already posted some answers to this question, I think I see where the issue might be coming from. The side that doesn't explicitly close the connection ends up in TCP state CLOSE_WAIT meaning that the connection is in the process of shutting down and waits for the side to issue its own CLOSE operation. I suppose it's fair enough that isConnected returns true and isClosed returns false, but why isn't there something like isClosing?

Below are the test classes that use pre-NIO sockets. But identical results are obtained using NIO.

```<code>import java.net.ServerSocket;
import java.net.Socket;

public class MyServer {
  public static void main(String[] args) throws Exception {
    final ServerSocket ss = new ServerSocket(12345);
    final Socket cs = ss.accept();
    System.out.println("Accepted connection");
    Thread.sleep(5000);
    cs.close();
    System.out.println("Closed connection");
    ss.close();
    Thread.sleep(100000);
  }
}

import java.net.Socket;

public class MyClient {
  public static void main(String[] args) throws Exception {
    final Socket s = new Socket("localhost", 12345);
    for (int i = 0; i < 10; i++) {
      System.out.println("connected: " + s.isConnected() +
        ", closed: " + s.isClosed());
      Thread.sleep(1000);
    }
    Thread.sleep(100000);
  }
}
</code>```

When the test client connects to the test server the output remains unchanged even after the server initiates the shutdown of the connection:

```<code>connected: true, closed: false
connected: true, closed: false
...
</code>```

答:
This is a flaw of Java's (and all others' that I've looked at) OO socket classes -- no access to the select system call.

Correct answer in C:

```<code>struct timeval tp;
fd_set in;
fd_set out;
fd_set err;

FD_ZERO (in);
FD_ZERO (out);
FD_ZERO (err);

FD_SET(socket_handle, err);

tp.tv_sec = 0; /* or however long you want to wait */
tp.tv_usec = 0;
select(socket_handle + 1, in, out, err, &tp);

if (FD_ISSET(socket_handle, err) {
   /* handle closed socket */
}
</code>```

OwnerDisplayName: Alexander

Body:
As a follow up to a recent question, I wonder why it is impossible in Java, without attempting reading/writing on a TCP socket, to detect that the socket has been gracefully closed by the peer? This seems to be the case regardless of whether one uses the pre-NIO Socket or the NIO SocketChannel.

When a peer gracefully closes a TCP connection, the TCP stacks on both sides of the connection know about the fact. The server-side (the one that initiates the shutdown) ends up in state FIN_WAIT2, whereas the client-side (the one that does not explicitly respond to the shutdown) ends up in state CLOSE_WAIT. Why isn't there a method in Socket or SocketChannel that can query the TCP stack to see whether the underlying TCP connection has been terminated? Is it that the TCP stack doesn't provide such status information? Or is it a design decision to avoid a costly call into the kernel?

With the help of the users who have already posted some answers to this question, I think I see where the issue might be coming from. The side that doesn't explicitly close the connection ends up in TCP state CLOSE_WAIT meaning that the connection is in the process of shutting down and waits for the side to issue its own CLOSE operation. I suppose it's fair enough that isConnected returns true and isClosed returns false, but why isn't there something like isClosing?

Below are the test classes that use pre-NIO sockets. But identical results are obtained using NIO.

import java.net.ServerSocket;
import java.net.Socket;

public class MyServer {
  public static void main(String[] args) throws Exception {
    final ServerSocket ss = new ServerSocket(12345);
    final Socket cs = ss.accept();
    System.out.println("Accepted connection");
    Thread.sleep(5000);
    cs.close();
    System.out.println("Closed connection");
    ss.close();
    Thread.sleep(100000);
  }
}

import java.net.Socket;

public class MyClient {
  public static void main(String[] args) throws Exception {
    final Socket s = new Socket("localhost", 12345);
    for (int i = 0; i < 10; i++) {
      System.out.println("connected: " + s.isConnected() +
        ", closed: " + s.isClosed());
      Thread.sleep(1000);
    }
    Thread.sleep(100000);
  }
}

When the test client connects to the test server the output remains unchanged even after the server initiates the shutdown of the connection:

connected: true, closed: false
connected: true, closed: false
...

LastEditorDisplayName: Alexander

Body:
This is a flaw of Java's (and all others' that I've looked at) OO socket classes -- no access to the select system call.

Correct answer in C:

struct timeval tp;
fd_set in;
fd_set out;
fd_set err;

FD_ZERO (in);
FD_ZERO (out);
FD_ZERO (err);

FD_SET(socket_handle, err);

tp.tv_sec = 0; /* or however long you want to wait */
tp.tv_usec = 0;
select(socket_handle + 1, in, out, err, &tp);

if (FD_ISSET(socket_handle, err) {
   /* handle closed socket */
}

OwnerDisplayName: Joshua


问:
php need help choosing player and format
I am in requirement of a player & video format that is supported on all desktop/laptop browser, and even on android and iphone, server is based on PHP

What I am right now using is .mov with H.264, which does not work on android, and sometimes not even in firefox

Help appreciated.

Thanks.

答:
The fact that you are using PHP is irrelevant because PHP doesn't do video processing.

If you're trying to do video processing, your best bet will be getting ffmpeg installed, which you can call from your PHP script to process video.

You're probably going to want to store videos in the following formats, in order of likely-to-be-playable-hood:

FLV, Flash's video container, combined with a Flash video player.  This will hit the largest chunk of your audience.

MPEG4 / H.264 will play in some systems that don't have Flash, including Apple's devices.  Watch out, the H.264 codec is burdened by software patents and a commercial licensing scheme.

WebM (sometimes known as VP8) will soon play in everything else that doesn't support Flash or H.264.

For formats 2 and 3, you'll want to look at the HTML5 video tag, which will work in all modern browsers.  Those modern browsers will also conveniently support those two formats.  You'll want to read that link for a great deal more information about video handling, including a section on WebM encoding using ffmpeg and sections on mobile devices.

(There's also Ogg Theora, but nobody loves it enough.)


答:
Use this query:

```<code>SELECT column_name
FROM table_name
WHERE LEFT(column_name, 4) >= value1 AND RIGHT(column_name, 4) <= value2
</code>```

I suggest that you better add another 2 columns for you year, and separate your years let say "year_from" and "year_to" and make this columns year as datatype.

Title: SQL query using Like and Between in the same statement

Body:
so here is my problem I need to select records in between year 2000-2008 but the columns I need to search for is in type varchar example:

IntRecordID     VARCHARYear
    1            1990-2000
    2            2001-2005
    3            2005-2006
    4            2007-2008
    5            2009-2020

select all record id that has VARCHARYear between 2000 and 2008

IntRecordID
    2
    3
    4

what is the sql query that I need to achieve this?

Body:
Use this query:

SELECT column_name
FROM table_name
WHERE LEFT(column_name, 4) >= value1 AND RIGHT(column_name, 4) <= value2

I suggest that you better add another 2 columns for you year, and separate your years let say "year_from" and "year_to" and make this columns year as datatype.


问:
Union All of SQL temporary tables created using dplyr?
How does one rbind or bind_rows temporary tables created in SQL (tested and failed in Postgres and SQLite) by dplyr?

E.g.

```<code>library(dplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), path = ":memory:")

copy_to(con, nycflights13::flights, "flights",
        temporary = FALSE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

copy_to(con, nycflights13::flights, "flights2",
        temporary = FALSE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

flights_db <- tbl(con, "flights")
flights_db_2 <- tbl(con, "flights2")
</code>```

Calling bind_rows gives the following error:

```<code>> bind_rows(flights_db, flights_db_2)
Error in bind_rows_(x, .id) :
  Argument 1 must be a data frame or a named atomic vector, not a tbl_dbi/tbl_sql/tbl_lazy/tbl
</code>```

答:
As database holds unique records, here both the objects 'flights', 'flights2' are the same.  Otherwise, we need

```<code>union(flights_db, flights_db_2)
</code>```

The above will only create the dimensions as in 'flights_db' because both the objects are the same.  If we need to create double the number of rows, then create a unique identifier

```<code>flights1 <- nycflights13::flights %>%
                  mutate(id= 1)

flights2 <- nycflights13::flights %>%
                  mutate(id = 2)

copy_to(con, flights1, "flights",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

copy_to(con, flights2, "flights2",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

flights_db <- tbl(con, "flights")
flights_db_2 <- tbl(con, "flights2")
</code>```

Now we do the union

```<code>union(flights_db, flights_db_2) %>%
                  summarise(n = n())
# Source:   lazy query [?? x 1]
# Database: sqlite 3.19.3 []
#       n
#   <int>
#1 673552

dim(nycflights13::flights)
#[1] 336776     19
</code>```

To demonstrate the uniqueness, we can select a small subset of disjointed rows for both the objects and then do the union

```<code>copy_to(con, nycflights13::flights[1:20,], "flights",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

copy_to(con, nycflights13::flights[21:30,], "flights2",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

flights_db <- tbl(con, "flights")
flights_db_2 <- tbl(con, "flights2")
union(flights_db, flights_db_2) %>%
          collect
# A tibble: 30 x 19
#    year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time arr_delay carrier flight tailnum origin  dest air_time distance
#   <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>     <dbl>   <chr>  <int>   <chr>  <chr> <chr>    <dbl>    <dbl>
# 1  2013     1     1      517            515         2      830            819        11      UA   1545  N14228    EWR   IAH      227     1400
# 2  2013     1     1      533            529         4      850            830        20      UA   1714  N24211    LGA   IAH      227     1416
# 3  2013     1     1      542            540         2      923            850        33      AA   1141  N619AA    JFK   MIA      160     1089
# 4  2013     1     1      544            545        -1     1004           1022       -18      B6    725  N804JB    JFK   BQN      183     1576
# 5  2013     1     1      554            558        -4      740            728        12      UA   1696  N39463    EWR   ORD      150      719
# 6  2013     1     1      554            600        -6      812            837       -25      DL    461  N668DN    LGA   ATL      116      762
# 7  2013     1     1      555            600        -5      913            854        19      B6    507  N516JB    EWR   FLL      158     1065
# 8  2013     1     1      557            600        -3      709            723       -14      EV   5708  N829AS    LGA   IAD       53      229
# 9  2013     1     1      557            600        -3      838            846        -8      B6     79  N593JB    JFK   MCO      140      944
#10  2013     1     1      558            600        -2      753            745         8      AA    301  N3ALAA    LGA   ORD      138      733
# ... with 20 more rows, and 3 more variables: hour <dbl>, minute <dbl>, time_hour <dbl>
</code>```

Body:
How does one rbind or bind_rows temporary tables created in SQL (tested and failed in Postgres and SQLite) by dplyr?

E.g.

library(dplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), path = ":memory:")

copy_to(con, nycflights13::flights, "flights",
        temporary = FALSE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

copy_to(con, nycflights13::flights, "flights2",
        temporary = FALSE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

flights_db <- tbl(con, "flights")
flights_db_2 <- tbl(con, "flights2")

Calling bind_rows gives the following error:

> bind_rows(flights_db, flights_db_2)
Error in bind_rows_(x, .id) :
  Argument 1 must be a data frame or a named atomic vector, not a tbl_dbi/tbl_sql/tbl_lazy/tbl

Body:
As database holds unique records, here both the objects 'flights', 'flights2' are the same.  Otherwise, we need

union(flights_db, flights_db_2)

The above will only create the dimensions as in 'flights_db' because both the objects are the same.  If we need to create double the number of rows, then create a unique identifier

flights1 <- nycflights13::flights %>%
                  mutate(id= 1)

flights2 <- nycflights13::flights %>%
                  mutate(id = 2)

copy_to(con, flights1, "flights",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

copy_to(con, flights2, "flights2",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

flights_db <- tbl(con, "flights")
flights_db_2 <- tbl(con, "flights2")

Now we do the union

union(flights_db, flights_db_2) %>%
                  summarise(n = n())
# Source:   lazy query [?? x 1]
# Database: sqlite 3.19.3 []
#       n
#   <int>
#1 673552

dim(nycflights13::flights)
#[1] 336776     19

To demonstrate the uniqueness, we can select a small subset of disjointed rows for both the objects and then do the union

copy_to(con, nycflights13::flights[1:20,], "flights",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

copy_to(con, nycflights13::flights[21:30,], "flights2",
        temporary = FALSE,
        overwrite = TRUE,
        indexes = list(
            c("year", "month", "day"),
            "carrier",
            "tailnum",
            "dest"
        )
)

flights_db <- tbl(con, "flights")
flights_db_2 <- tbl(con, "flights2")
union(flights_db, flights_db_2) %>%
          collect
# A tibble: 30 x 19
#    year month   day dep_time sched_dep_time dep_delay arr_time sched_arr_time arr_delay carrier flight tailnum origin  dest air_time distance
#   <int> <int> <int>    <int>          <int>     <dbl>    <int>          <int>     <dbl>   <chr>  <int>   <chr>  <chr> <chr>    <dbl>    <dbl>
# 1  2013     1     1      517            515         2      830            819        11      UA   1545  N14228    EWR   IAH      227     1400
# 2  2013     1     1      533            529         4      850            830        20      UA   1714  N24211    LGA   IAH      227     1416
# 3  2013     1     1      542            540         2      923            850        33      AA   1141  N619AA    JFK   MIA      160     1089
# 4  2013     1     1      544            545        -1     1004           1022       -18      B6    725  N804JB    JFK   BQN      183     1576
# 5  2013     1     1      554            558        -4      740            728        12      UA   1696  N39463    EWR   ORD      150      719
# 6  2013     1     1      554            600        -6      812            837       -25      DL    461  N668DN    LGA   ATL      116      762
# 7  2013     1     1      555            600        -5      913            854        19      B6    507  N516JB    EWR   FLL      158     1065
# 8  2013     1     1      557            600        -3      709            723       -14      EV   5708  N829AS    LGA   IAD       53      229
# 9  2013     1     1      557            600        -3      838            846        -8      B6     79  N593JB    JFK   MCO      140      944
#10  2013     1     1      558            600        -2      753            745         8      AA    301  N3ALAA    LGA   ORD      138      733
# ... with 20 more rows, and 3 more variables: hour <dbl>, minute <dbl>, time_hour <dbl>